Set the number of choices available using multiple select with Chosen.js .
Sometimes when you're using Chosen.js's Multiple Select you want restrict the number of choices. Here a little code snippet to achieve it.
In this example I want the user to choose maximum 2 options
$('#id').chosen().change(function(event) {
if($(this).val()!=null){
if ($(this).val().length > 1) {
$(".chzn-drop").css("display","none");
}
if ($(this).val().length < 2) {
$(".chzn-drop").css("display","block");
}
}
});
Written by Esteban Arango Medina
Related protips
1 Response
Thank you so much, dude!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#