lou / multi-select

A user-friendlier drop-in replacement for the standard select with multiple attribute activated.
loudev.com
MIT License
1.9k stars 439 forks source link

How to remove all options? #268

Open longqnh opened 7 years ago

longqnh commented 7 years ago

Dear all, If I have a multiselect like:

<select id='pre-selected-options' multiple='multiple'> <option value='elem_1'>elem 1</option> <option value='elem_2'>elem 2</option> <option value='elem_3'>elem 3</option> <option value='elem_4'>elem 4</option> </select>

$('#pre-selected-options').multiSelect();

I wanna remove all options in #pre-selected-options. How can I do it?

TiedtTech commented 7 years ago

View this post https://github.com/lou/multi-select/issues/193

$('#my-multi').empty().multiSelect('refresh');

brmendez commented 6 years ago

I am trying to do something like this: $mySelect.empty().multiSelect('refresh').multiSelect({ allMyOptions }); so that my table will be reinitialized each time my function is called, at which point new options will repopulate in my multiSelect.

allMyOptions contains many pieces of logic and events that I need to run, ex: afterSelect, afterDeselect

but... multiSelect('refresh') invalidates all my options/events.

My multiSelect contains a list of user roles. Some of those roles are disabled, some are enabled. Refresh invalidates that logic, but I don't want it to.

I have also tried: $multiSelect('destroy').multiSelect({ allMyOptions }); but this does not actually reinitialize the multiSelect.

I am at a loss... any suggestions?

mike1000000000 commented 6 years ago

This is what worked for me.

Add into the jquery.multi-select.js (under the destroyer - or in that section):

    'removeAllOptions' : function(){
    this.destroy();
    this.$element.find('option').remove();
    this.$element.multiSelect({});
 },

Then call: $('#my-select').multiSelect('removeAllOptions');

ahsan013 commented 5 years ago

Try This Removing Options for Multiple Select Drop Down.

$('#FeatureId').multiselect("deselectAll", false).multiselect("refresh");

ahmedabushaaban commented 5 years ago

View this post #193

$('#my-multi').empty().multiSelect('refresh');

this works perfect, but it remove the optgroup how to keep the groups or add them again ?

MuhammadMamduh commented 4 years ago

@ahmedabushaaban how can i remove the ptgroup ???

akambaram commented 4 years ago

when we use this $('#my-multi').empty().multiSelect('refresh'); select header details are also not displaying.

arbazdiwan commented 4 years ago

Do this...

$("#my-multi option:selected").prop("selected", false); $("#my-multi option").remove(); $('#my-multi').multiselect('rebuild');

kuldeep111 commented 3 years ago

working for me $("#selectedVariables option:selected").prop("selected", false); $("#selectedVariables option").remove(); $('#selectedVariables').multiselect('rebuild');

Samirdatainflow commented 2 years ago

View this post #193

$('#my-multi').empty().multiSelect('refresh');

Thank you so much, it work properly.

YashKachariy commented 2 months ago

$("#my-multi option:selected").prop("selected", false); $("#my-multi option").remove(); $('#my-multi').multiselect('rebuild'); work perfect you have to adjust $('#my-multi').multiselect('rebuild'); up-down