asantibanez / laravel-blade-sortable

Custom Blade components to add sortable/drag-and-drop HTML elements in your apps.
MIT License
409 stars 79 forks source link

Deleting sortable-item #10

Closed Hesesses closed 2 years ago

Hesesses commented 3 years ago

Hello,

I have multiple sortable lists:

group 1

group 2 (no teams)

group 3 (no teams)

sample code:

@foreach ($groups as $group)

                    <x-laravel-blade-sortable::sortable
                        group="teams"
                        name="{{ $group->id }}"
                        wire:onSortOrderChange="groupChanged"
                    >
                        @foreach ($group->teams as $team)
                            <x-laravel-blade-sortable::sortable-item
                                sort-key="{{ $team->id }}"
                            >
                                <div>
                                    {{ $team->name }}
                                </div>
                            </x-laravel-blade-sortable::sortable-item>
                        @endforeach
                    </x-laravel-blade-sortable::sortable>
                @endforeach

I have a function that can remove a group. ($groups is updated)

If I remove the group2, then each groups after that breaks... for example when group 2 is removed and i try to move a team from group 1 to group 3 groupChanges will receive the following params:

0: ["..."]
1: ["..."]
2: "group 2" <- this is already deleted, should be group 1
3: "group 1"
4: "group 3"

Any ideas whats wrong?

laraben commented 3 years ago

@Hesesses groupChanged function is probably wrong. Can you show your livewire component please?

Hesesses commented 2 years ago

I tried this on another project and it seems to be working, i probably messed something earlier