Make select2_multiple sortable
P粉006540600
P粉006540600 2024-03-29 18:20:40
0
1
472

How do we make select2_multiple sortable? I have a users table and a badges table. Of course, I want a user_badge pivot table that will track all the badges a user has and sort them based on the order I define using select2_multiple.

Currently, my setupCreateOperation() is set up as follows:

protected function setupCreateOperation()
{
    $this->crud->addField([
        'name' => 'badges_multi',
        'label' => 'Badges',
        'type' => 'select2_multiple',
        'attribute' => 'internal_name',
        'entity' => 'badges_multi',
        'model' => 'App\Models\Badges',
        'pivot' => true,
        'sortable' => true,
        'sortable_options' => [
            'handle' => '.my-custom-handle',
        ],
    ]);
}

This returns select2_multiple but the input is not sortable, i.e. I can drag and drop to rearrange. It only returns badges

in alphabetical order
P粉006540600
P粉006540600

reply all(1)
P粉478445671

select_multiple The field has no sorting function.

To order, you can use the select_and_order field or repeatable field

If you want to implement it this way, you can also create a custom version of the select_multiple field with order functionality.

Executionphp artisan Backpack:field select_multiple_with_order --from=select_multiple will create a new file in the resources folder same as Backpack select_multiple, from there you can add the required functionality and in other Reuse it in CRUD if you need it too.

Wish you all the best.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template