Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PATRICK SPRINGSTUBBE jQuery multiselect plugin for single select

I am using Patrick Springstubbe multiselect pluging and it works fine. But now I would like to use it for single select. I know I need to set the select to mulitple for the plugin to work. But is there a way to limit the number of option to 1.

I have tried

$("#ProductCategory").change(function(){

  $(".ms-options").css("visibility","hidden");
  
  }

This gives the desired effect when you select an option but then you can reopen the list. I have tried using a function on $("#ProductCategory").click but this did not work.

like image 953
Sheils Avatar asked Apr 29 '18 21:04

Sheils


1 Answers

As Kavindra sugested, it is better to look for a plugin that already does the job you need.

In case you still want to use that plugin and have single selection you can try this:

$('#mySelect').next().find('input[id^="ms-opt"]').click(function(){ 
   $('.ms-options input[id^="ms-opt"]:checked').not(this).click(); 
})

Here's the fiddle: https://jsfiddle.net/1jfwp81d/3/

I added two selects, one with single and another with multiple selection working together.

Note that this is a hack and might not work with newer versions of the plugin.

like image 76
AarónBC. Avatar answered Nov 17 '22 09:11

AarónBC.