How do we make a select2_multiple
sortable? I have a users
table and a badges
table. Naturally, I want to have a user_badge
pivot table which will keep track of all the badges a user has and also sort it based on the order that I define using the select2_multiple
.
Currently, I have my setupCreateOperation()
setup 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 the select2_multiple
but the input is not sortable, ie I can drag and drop to rearrange. It only returns badges in alphabetical order
The select_multiple
field does not have the ordering functionality.
To order you can use the select_and_order field or the repeatable field
You can also create a custom version of the select_multiple
field that has the order functionality if you want to implement it that way.
Doing php artisan backpack:field select_multiple_with_order --from=select_multiple
would create you a new file in your resources folder that is equal to Backpack select_multiple, from there you can add the functionality you need, and re-use it in other cruds if you need it there too.
Wish you the best.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.