Hi friends, I am creating a drag and drop template creator with Phoenix LiveView
and sortable js
.
When my user drops an element, I create div
s with custom unique IDs and append them as a Dom
.
All the js Hook and phx
events work except when my state is updated, for example:
def handle_event("delete_access", %{"id" => id, "type" => "section-drag"}, socket) do
{:noreply, assign(socket, :section_id, id)}
end
after updating the assign socket parameters, it resets and deletes all the created drag/drop elements which are created by sortable js
I put phx-update
based on my experience, the first one phx-update="ignore"
it allows me to put my JS code, and it has some limitation for example the changes are implemented in the same parent div is not shown
If I use append
or prepend
it shows me an error and say go delete the illegal node which has no ID, If all my elements have an ID
Please see this video:
JS example Code:
Sortable.create(getBlocks, {
group: {
name: 'LayoutGroup',
pull: 'clone',
put: false,
},
animation: sortableSpeed,
sort: false,
onStart: function (evt) {
previewHelper.classList.add('hidden');
},
onEnd: function (evt) {
if (putBlock.children.length === 1) {
previewHelper.classList.remove('hidden');
} else {
...
}
},
});
Thank you in advance