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
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.
Most helpful comment
@tabacitu - Could it be related to https://select2.org/selections#clearable-selections?
The config option is named
allowClear