Reputation: 893
I am hiding a particular option from chosen dropdown. I cannot remove it tout court because I need that option on IE6 (!).
The problem that I have is that when I start typing in the input field that hidden option reappears among chosen search results.
I also tried to use the {display_disabled_options: false
} option but it is not working (maybe because I am disabling the option after chosen has already been initialized.
I am trying to do this:
$(".chosen-select").chosen({
display_disabled_options: false
}).each(function () {
$(this).on('chosen:showing_dropdown', function (event, params) {
$('li:contains("whatever")').attr('disabled', true);
});
});
Upvotes: 1
Views: 2460
Reputation: 30993
If you need to update the list after chosen initialization you need to trigger its update using trigger("chosen:updated")
.
So use the code:
$(function () {
$('.chzn-select').chosen({
display_disabled_options: false
}).each(function () {
$(this).on('chosen:showing_dropdown', function (event, params) {
$('option:contains("shop")',$(this)).attr('disabled', true);
$(this).trigger("chosen:updated");
});
});;
});
Demo: http://jsfiddle.net/IrvinDominin/NfvBj/
Upvotes: 1