Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Problem with livewire-sortable with dynamic array

Hello,

I manage an array to display a list that contains a form with identical groups of fields. I have an ADD button to add a new group of fields. No problem to save the items in the database. The problem is related to the drag and drop.

I'm using livewire-sortable to sort the items. When I open the form, there are two cases :

Case 1 - the list has already some items and it displays the list of the existing items

Case 2 - the list is empty and I have to click on the ADD button to add the first group of fields

Case 1 : I have no problem to drag and drop via the handle, I can add some new groups of fields and there is once again no problem to drag and drop.

Case 2 : all the added groups of fields have a strange behavior when I attempt to drag and drop them => it's possible de drag the items from anywhere on the item whereas I have a handle and when I drop the item, it can be dropped anywhere.

It looks like a problem I had when I had forgotten to add a key to the livewire component. But here it's perhaps the same behavior, but not the same problem because it works fine with an existing list. So I think about perhaps the initialization of the script when the list is empty.

Do you have any idea about the origin of this problem ?

Thanks a lot.

Vincent

0 likes
2 replies
vincent15000's avatar

I've not succeeded to solve this issue yet. I think that the problem comes from the refresh of the livewire component when it display a new item in the list => I think that the dynamically added new item is not initialized with the JS code in livewire-sortable.

If you have any idea how to solve this issue ;) ...

ibeeeee's avatar

Hello, have you resolved this problem, because i have same issue like you and don't have idea how to handle that

1 like

Please or to participate in this conversation.