Reorder fields in an ArrayCollection in Symfony form

I use a Symfony form for display a collection of BlockType who have each a "position" field.

On the view, it’s possible to re-order each block by clicking on up/down/remove buttons:

Here all work fine

enter image description here

enter image description here

All positions is everytime updated with javascript when I click on a button.

But I have a problem.
When I submit the form, inside the array collection, all position is OK, but the array collection is not ordered by block.position, result: if the form has an error, it is displayed again, but without block.position ordering (it’s the old order used, order during form init).

Is it possible to fix this problem in php please?

enter image description here

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *