search

Home  >  Q&A  >  body text

Make select2_multiple sortable

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粉006540600P粉006540600285 days ago501

reply all(1)I'll reply

  • P粉478445671

    P粉4784456712024-03-30 11:37:11

    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.

    reply
    0
  • Cancelreply