bootstrap-multiselect icon indicating copy to clipboard operation
bootstrap-multiselect copied to clipboard

Issue with deselectAll and radio multiselect (multiple = false)

Open zephyx opened this issue 9 years ago • 7 comments

Hi,

When I try to clearSelection my multiselect the label of the multiselect is properly reset but when I open my multiselect the previous radio button chosen is still checked. If I am not wrong I think it probably comes from the deselectAll function where only the checkbox case is handled.

I have added a:

var type = this.options.multiple === true ? "checkbox" : "radio"; And I use this variable inside the js selectors (ie: $("li input[type='"+type+"']:enabled" ) and it seems to work. It's important for me because I trigger something on the change event :). If a value is already selected we can't fire the change event except if we select an other option and come back later.

zephyx avatar Jan 22 '15 17:01 zephyx

Might be related to #129! I will check this, however, as stated in #129 and as I remember, a part of this problem is also due to browser behavior.

davidstutz avatar Feb 12 '15 23:02 davidstutz

If the problem is the browser behaviour, may be it could at least select the first radio option by default when we deselectAll ? In this case it would correspond to the default state of a select on all browser like if nothing had been selected first.

zephyx avatar Feb 17 '15 14:02 zephyx

I had to do a refresh: $('#myMS').multiselect('refresh'); to get rid of the previously selected item.

kayday avatar Feb 17 '15 23:02 kayday

+1 In our case, we have several dropdowns, and 1 button that clears them all. Unfortunately, after clearing (using 'clearSelection()') them it's not possible to re-select the previous selection (unless you select something else first).

To fix this, I've swapped out the 'change' events for 'click' events. That fixes the issue, and also fixes a related bug where the dropdown won't close if you click on an option that's already selected.

Is there a reason why the 'change' event is used instead of the 'click' event? I don't see any downside to switching to 'click'.

EoinGriffin-AI avatar Jan 27 '16 01:01 EoinGriffin-AI

Not sure whether the click event screws up keyboard support. Might check it first before switching.

davidstutz avatar Oct 22 '17 21:10 davidstutz

@zephyx did your provided solution ever got into the source code and released as I am facing the same issue in 2020 while using the plugin.

I used various combinations of .val(''), .multiselect('resfresh'), .multiselect('deselectAll', false), and .multiselect('updateButtonText') as suggested in docs and many issues and although a specific combination resolves the issue at the browser side of clearing the selected radio button however when the values is submitted back to the server, it has the last "default / selected" option as selected.

What are the recommendations?

moghazali-iomosaic avatar Aug 18 '20 12:08 moghazali-iomosaic

Same issue here. unselectAll doesn't work. Unselection for all options works only using the following lines:

$('.myselect').val('');
$('.myselect').multiselect('refresh');

foxbit19 avatar Oct 09 '20 12:10 foxbit19