Here is the solution:
$(function() { var cSelect = $('.chzn-select').chosen(); var allItem = cSelect.find("option[value='ALL']"); //reference to the "ALL" option var rest = cSelect.find("option[value!='ALL']"); //reference for the rest of the options var allItemAlreadySelected = true; //set a flag for the "ALL" option previous state cSelect.change(function(event) { if ($(this).find("option:selected").length == 0) //if no selection { allItem.prop('selected', true); //select "ALL" option } else { if (allItem.is(':selected')) //currently "ALL" option is selected, but: { if (allItemAlreadySelected == false) //if previously not selected { rest.prop('selected', false); //deselect rest allItem.prop('selected', true); //select "ALL" option } else //if "ALL" option is previously selected (already), it means we have selected smthelse allItem.prop('selected', false); //so deselect "ALL" option } } allItemAlreadySelected = allItem.is(':selected'); //update the flag $('.chzn-select').trigger("liszt:updated"); //update the control }); });
Now you don’t need the placeholder at all. now management never becomes empty. So, to get rid of the placeholder, all you have to do; add this attribute to your select .
data-placeholder=" "
The value must have a space , otherwise the selection may overwrite it.
<select data-placeholder=" " id="customTextFilterSelect" multiple='multiple' style="width:350px;" class="chzn-select">
Here is the working code on jsFiddle .
source share