multi-select icon indicating copy to clipboard operation
multi-select copied to clipboard

How to remove all options?

Open longqnh opened this issue 8 years ago • 11 comments

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?

longqnh avatar Apr 09 '17 08:04 longqnh

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

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

TiedtTech avatar Jun 06 '17 15:06 TiedtTech

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?

brmendez avatar May 10 '18 22:05 brmendez

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');

mike1000000000 avatar Jul 11 '18 04:07 mike1000000000

Try This Removing Options for Multiple Select Drop Down.

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

ahsan013 avatar Oct 05 '18 20:10 ahsan013

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 ?

ahmedabushaaban avatar Mar 31 '19 23:03 ahmedabushaaban

@ahmedabushaaban how can i remove the ptgroup ???

MuhammadMamduh avatar Oct 12 '19 19:10 MuhammadMamduh

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

akambaram avatar Nov 09 '19 09:11 akambaram

Do this...

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

arbazdiwan avatar Jan 23 '20 06:01 arbazdiwan

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

kuldeep111 avatar Aug 31 '21 17:08 kuldeep111

View this post #193

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

Thank you so much, it work properly.

Samirdatainflow avatar Sep 25 '21 07:09 Samirdatainflow

$("#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

YashKachariy avatar Jun 14 '24 05:06 YashKachariy