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

Submit droped items (in order) #3

Closed WL1981 closed 3 years ago

WL1981 commented 3 years ago

Hello,

How to store/submit droped items (in order)?

DRAG FROM:

    <x-laravel-blade-sortable::sortable group="orders">
       @foreach($orders as $order)
          <x-laravel-blade-sortable::sortable-item as="div" sort-key="{{ $order->id }}" class="bg-theme-gray-500 my-1 px-5 py-5 text-white">{{ $order->id }}</x-laravel-blade-sortable::sortable-item>
       @endforeach
    </x-laravel-blade-sortable::sortable>

DROPED IN:

<form method="POST" action="{{ route('selected_orders.update', $workday->id) }}" class="py-6 px-10">
    @csrf
    @method('PATCH')
    <x-laravel-blade-sortable::sortable group="orders" name="sort_order">
          <!--- DROP ZONE --> 
    </x-laravel-blade-sortable::sortable>

    <button type="submit">Submit</button>
</form>
WL1981 commented 3 years ago

Fixed by adding a hidden input in the main loop. Inputs are not created automatically after a drop in the drop-zone

<input name="selection[]" type="hidden" value="{{$order->id}}">
asantibanez commented 3 years ago

Hi @WL1981

I'll check this one. It makes sense to be able to submit both droppable containers. 👍

asantibanez commented 3 years ago

Hey @WL1981

Check out v1.1.0.

Just add a name prop to each <x-laravel-blade-sortable::sortable> and you get those hidden inputs with the order 👌