Crud: select2 multiple add all / remove all features

Created on 18 Aug 2017  路  5Comments  路  Source: Laravel-Backpack/CRUD

I cannot find documentation if this is implemented, but in a select2 mulitple it will be ~handful~ useful? for user to have an option to select all or remove all.

This was implemented I think on select2 already but not sure if ported to Backpack CRUD

https://github.com/select2/select2/issues/195

This is for select2_from_array

help wanted question

Most helpful comment

@tabacitu - Could it be related to https://select2.org/selections#clearable-selections?

The config option is named allowClear

All 5 comments

Not ported here (yet) from what I can tell.

Probably want to make this work for all types of select(2)s.

Just for now I am using a work around, created 2 buttons ALL and CLEAR and added this script:

var $select2Multi = $('select[name="fieldName[]"]');
$("#clear").on("click", function ( event ) {
    event.preventDefault();
    $select2Multi.val(null).trigger("change");
});
$("#all").on("click", function ( event ) {
    event.preventDefault();
    $select2.select2('destroy').find('option').prop('selected', 'selected').end().select2()
});

@MickaelTH - I can't find this in the select2 docs to see its syntax. Could you please point me in the right direction?

If they implemented this in the core, I'm wondering if it's as easy as specifying some attributes on the field type. In that case, we only need to use the updated JS and it would work.

@tabacitu - Could it be related to https://select2.org/selections#clearable-selections?

The config option is named allowClear

Closing due to inactivity; feel free to reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

genesiscz picture genesiscz  路  3Comments

gotrecillo picture gotrecillo  路  3Comments

M0H3N picture M0H3N  路  3Comments

sseggio picture sseggio  路  3Comments

sonoftheweb picture sonoftheweb  路  3Comments