I have an select with some option’s:
<select id="select">
<option>1</option>
<option disabled="true">2</option>
<option>3</option>
</select>
I’m using Chosen Plugin for jQuery and the problem is that disabled options are removed from the view. But I need to show it as unclickable disabled elements.
Is there any chance with jquery chosen plugin?
—
The example would transformed to:
<ul class="chzn-results">
<li id="location_select_chzn_o_0" class="active-result result-selected">1</li>
<li id="location_select_chzn_o_2" class="active-result">3</li>
</ul>
So the secound element is not made unvisible, it simply not exist.
You will need to edit the plugin as outlined here :
http://bitsmash.wordpress.com/2012/10/01/making-disabled-elements-visible-with-the-jquery-chosen-plugin/
The plugin reads in a select, removes it from the DOM, and adds a new ul. Options marked “Disabled” are skipped when adding li to the new ul
Here is the method of interest in chosen.jquery.js
Notice that if an option is disabled it returns nothing. Take the line
and put in the html/css you would like for a disabled item. Or, you can remove the if (!option.disabled) block, and add a new if (!option.disabled) block that adds a special CSS class if the item is disabled.
Next, you need to make sure when users click a disabled item nothing happens. You need to edit this method :
Add a block that says, if disabled, return false, then when users click on that item nothing will happen.