I am trying to use input field to do interaction of on change. Onchange interaction will update state of state variable inputValue which is an array. Inside inputValue there are alot of objects. And I need to just change one of the objects in side value.
in example, I want to change object {“id”: “7”, “type”: “dropdown”, “answer” : “”}. I want to only update the value of answer. How can I do that using the interaction?
Anyone can help me with this?
I understand your data structure as something like:
[
{
“id”: “6”,
“type”: “dropdown”,
“answer” : “”
},
{
“id”: “7”,
“type”: “dropdown”,
“answer” : “”
}
]
If so, in your interaction you can choose “Run Code” as the action and use a JS one liner like so to update the array object directly:
$state.inputValue[1].answer = "myNewValue"
The above assumes you already know the array index (i.e. from the currentIndex variable in plasmic)
If you don’t know the array index, you could filter for it based on the object values (e.g. the id key) like is mentioned here: javascript - Get the index of the object inside an array, matching a condition - Stack Overflow