Chosen plugin max_selected_options -


i use chosen jquery plugin , noticed max_selected_options not working:

the code this:

<!doctype html>  <html lang="en">  <head>     <link rel="stylesheet" href="chosen/chosen.css" /> </head> <body>  <select id="assets" data-placeholder="choose assets" class="chzn-select" multiple style="width:350px;" tabindex="4">     <option value="a">a</option>     <option value="b">b</option>     <option value="c">c</option>     <option value="d">d</option>     <option value="e">e</option>     <option value="f">f</option>     <option value="g">g</option> </select>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script> <script src="chosen/chosen.jquery.js" type="text/javascript"></script> <script type="text/javascript">        $(document).ready(function(){         $(".chzn-select").chosen();         $(".chzn-select-deselect").chosen({allow_single_deselect:true});         $('.chzn-select').chosen({ max_selected_options: 3 });         $(".chzn-select").bind("liszt:maxselected", function () { alert("a"); });         $(".chzn-select").chosen().change( function () { alert("a"); } );     });  </script> </body> </html> 

i don't understand incorrect code. line:

$('.chzn-select').chosen({ max_selected_options: 3 }); 

should limit maximum number of allowed selections. doesn't work. still can select number of items. noticed event should fired on case maximum number of selected items reached doesn't fire:

$(".chzn-select").bind("liszt:maxselected", function () { alert("a"); }); 

do have error in code?

and 1 more question: how can add search functionality list, search box appears on first example on plugins page?

thanks.

you call twice chosen() method, why problems:

$(".chzn-select").chosen(); $('.chzn-select').chosen({ max_selected_options: 3 }); 

remove first 1 , works. js code should be:

$(document).ready(function(){     $(".chzn-select-deselect").chosen({allow_single_deselect:true});     $(".chzn-select").chosen({ max_selected_options: 3 });     $(".chzn-select").bind("chosen:maxselected", function () { alert("max elements selected"); });     $(".chzn-select").chosen().change( function () { alert("change"); } ); }); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -