Access Sorted Index in FormRepeat

Hello,
I need the index of the form-repeat items after reordering them via the “sortable” option by drag and drop. As you can see below, I display the $index of the item as a Heading using a Dynamic Attribute binding, but after reordering them, the index doesn’t change, even though the order the items are displayed in has changed. How do I access the index of the order they are displayed in?

Dynamic Value Binding the index of the FormRepeat:
image

Index display before reordering:
image

Index display after reordering with “sortable” using drag&drop:
image

Is there any news on this? Is this a bug/missing feature or am I overlooking something?

What is the use-case for this and in what kind of data format would you want this? When submitting the form it should already submit the items in the new order.

I have a list of objects that the user is supposed to be able to change the order of, so I want to send the index of each object to the backend in order to save the order of objects.
It would add an extra step if I were to extrapolate the index by using the order the items are submitted in. But even so, I can see in the Request Payload that the order the items are submitted in via FormRepeat doesn’t change even after dragging & dropping them into a different order. They seem to be always submitted in the order they were originally inserted into the Form Repeat, so this workaround wouldn’t work either way.
I’m using an API Form for submitting the FormRepeat data.

Are there any plans to address this?

The form always submit the data in the order as it appears in the DOM. So reordering inputs in the DOM will also update the order of the data that is being submitted.

It doesn’t though.

This is the initially displayed order of items submitted:
image
This is the Response preview on submitting the list in the initial order:
image
Note the descending order of item_ids.

Now, I rearrange the items per drag and drop to this order:
image

If I submit the form, this is the Response Preview that I get:
image

Which is the exact same order as it was before, despite dragging the FormRepeat items into a new order.

I would appreciate an update on this.

Bumping this.

Same thing happened to me several times. I moved my input fields into a separate container in the form and that resolved the issue.

From this:
Screen Shot 2022-12-15 at 15.26.28

To this:
Screen Shot 2022-12-15 at 15.26.14

1 Like

Thank you @cem. I know this is an old thread but it was just happening to me as well. Always, submitting in the original order. I was banging my head against the wall till I saw your comment.

I simply had a row and columns with the inputs and it was not sending them in the sorted order:

I put the row in a flex container and voila, sorting is submitting in the expected order. Bizarre.
Screenshot 2024-02-02 at 6.46.37 AM

Spoke too soon. Putting in the flex container stops it from always submitting in the original order, but now it is submitted the order before the current sort order that I do. Experimenting some more. I have the form submitting onEnd of the drag and drop. Must be the DOM not updating quick enough.

This should better explain it. I made the ids visible in the sort so you can see which order they are supposed to be in, and which they are actually submitting.

-Twitch