Dynamic form only updates in studio/event handles do not work.

Ticket: Dynamic Actions Array Configuration in Plasmic Form List

Problem Description

I have a form group called actions with the initial value of actions[{ type_id: null }] where type id is a drop down, this group has multiple form fields that should populate when the array has more values, all depending on the dropdown selection.
in that same group i have a empty form field with the currentindex as the key which automatically populates object 0, 1, and so on. with the initial value of:

which is fetched through $state.buttonconfig.find(u => u.type_id === currentItem.type_id)

that variable returns something like this:

{
      "type_id": "maps",
      "name": "Maps",
      "label": "Find Us",
      "prefix": "https://maps.google.",
      "icon_url": "maps_icon.png",
      "validation": {
        "type": "text",
        "pattern": ""
      }

this all works perfectly in the studio, the complete object populates every time i change the dropdown value which is the “type_id”

the issue begins when i try outside of the studio, even when i change the dropdown value nothing populates, i concluded that that happens because the initial value does not update dynamically outside of the studio which seems logical, the issue now is that i have tried dozens of ways to fix this and nothing works.

here is what i tried.

1.-using the list component instead of repeating the group. same issue the initial value of the list does not update with the changes of the dropdown to fetch the data.

2.- using the dropdown on value change handler. for some reason the handlers are absorbed by the form field when they are their children and stop working, which is another issue all by itself.

3.- Using a data provider inside and outside of the form field, inside does not read its value even when i match the value prop, outside even though it fetches the data correctly i cant find a way to pass the data to a form field, if i do it in initial value it wont update just like before.

4.- trying to use a component inside the form field called “currentIndex” where its value is the $state.buttonconfig.find(u => u.type_id === currentItem.type_id), this is the closest i’ve been however all components expect a string value, when the value is an object i get a react error (even though the form field it does get the value), if i could find a form component that its value is an object or an array that could work.

5.- tried creating a custom component with an object state variable for the form field to take the object value. i just could not make the form field read the value of the children component, even after naming the prop/state value and the handler onChange.

using all sorts of codes to update the array like:

[
  {
    type_id: null
  },
  ...(type_id !== null 
    ? ($state.buttonconfig.filter(config => config.type_id === type_id) || []).map(config => ({ ...config }))
    : [])
]

or super complex functions using proxies. same issue, since the initial value is not dynamic i cant do it.

6.- using the dependencies field. this only retriggers the validation.

All i need is for a form field to update other form fields is there a way to that? it sounds like such a simple thing to do but i just can’t find a way to do so. i also don’t want to introduce state variables since that can potentially break the array in the future, if im able to do it though the form field alone i could add or delete variables from the initial value array and will still work perfectly. thats also why im using the current index.

Reproduction Steps

  1. Create a Form List in Plasmic
  2. Add a JavaScript box to define the actions array
  3. Set initial configuration to [ { type_id: null } ]
  4. Attempt to dynamically update the array when type_id changes

Code Example of Current Attempt

[
  {
    type_id: null
  },
  ...(type_id !== null 
    ? ($state.buttonconfig.filter(config => config.type_id === type_id) || []).map(config => ({ ...config }))
    : [])
]

I hope someone can help me with this, thank you!.

Please share your project Id and the component name/id

sure, I couldn’t find the project id but here is the page, which is called model upload inside my project

https://studio.plasmic.app/projects/mfM8aAQAaRBGSjMQFf63Y1/-/Model-upload?arena_type=page&arena=QbLZBsrkOs36

as per the component specifically it is “Button one selection. 3” however this is more of a global issue, I don’t know how to populate multiple form field values with the change of one of the fields. also all form components loose their even handlers when they are inside a form field as children.

thanks for the help

Thank you for the details.
This is probably a bug in the form item components, but you should be able to update the form’s initial value in preview. Also, have you tried to achieve this with the “On values change” event handler on the form?

yes I can change the forms initial value or forms field initial value, but thats the issue, that only the initial value. if for example a form field’s value is $state.component_x + 10 the value will not change even if the user changes the value of $state.component_x. the initial values do not update dynamically even when using dynamic values.

secondly I cant use the dynamic value in the actual components value, because the value field gets absorbed by the form field, I believe that why the event handlers break, here is a example of the same component, first inside and second is outside.


and even if I were to put the formula in the value before I put it in the form field, it gets overwritten and ignored. so I cant find a way to make form fields depend on dynamic values.

as per the form on change handler, since it is outside of the repeatable components and cant make use of the “currentIndex” variable. I have to hardcode the variable names a paths to a dynamic object, instead of the field being key “x+currentitem” I would have to set up the interaction as $state.aaSplashForm.value.features.actions.(the key of that component or “.X0” )
making it extremely dangerous and not advisable for shemas that build themselves depending on the day such as a form, if the items is non existent, any of the keys changes, an object is now nested inside another object etc. the logic would break returning undefined. this could also happen for the objects the are not there yet, which current index solves. this would also introduce countless conditionals wiring like 8 components the same way 4 times each :sob:.

I really have no idea what to do. this is a basic feature of all design system forms though the dependancies field, usually you set it up like

// Example of how dependencies should behave
{
“formFields”: {
“price”: {
“value”: 100,
“dependencies”: [“quantity”, “taxRate”],
“calculate”: “(quantity * basePrice) * (1 + taxRate)”
},
“total”: {
“value”: 0,
“dependencies”: [“price”, “shipping”],
“calculate”: “price + shipping”
}
}
}

but I think antd forgot to make this available when creating the components. you can only edit what’s inside the dependancies field. I just haven’t been able to find it. I think if the form field showed the children’s event handlers that would be the solution.

again any advise would be greatly appreciated.

into states, which would essentially break the need of using a form