Update single array item

Updating single items in an array.

Why update single item?

In RUAL you have multiple field types. One of them is an Array. To edit an array field, you can use the form: array input. The input will create inputs for every item in the selected array. With the array input you can edit arrays of all different types, Values, Numbers, Objects, etc. To render the array input for either a value or a number, you just need to let the manage field of the action empty. For the object arrays, you can fill the manage fields with the fields you want to edit from that object. Using the array input in either of these ways you can edit any of the items also one of the items. This will always work. In some cases you want only to show and edit one of the items from the array. This will require i tiny bit more work.

update_array_why.png

Index based

The solution to update only one item in the array, you will need to use the indexes of the items. When the item you want to edit is always in a fixed place you can use the example to the right. The first item of the array is always 0. From there it is every-time +1.

update_array_index_based.png

Dynamic index

Most likely you will not be able to use static indexes to get the item from the array. For this you will need to find the index from the array. The method to do this for the different field types we have is different. You can use the index of action to get the index of Values, Numbers, Dates and Booleans. You can use this index, cast it to a value and concat it with the array field.

To get the index of an item in an array with objects you need to use the array find by key - value. With this action you can fill in the key (field from the object you want the value to match) and the value. The value can be changed from type. The action will return the Results and the indexes from all the different items that matches the key -> value combination. When you are sure the array only has one match to your combination. You can use the get first item (number) from the Indexes out-pin and use that in you field.

update_array_dynamic_index.png