I have 3 multiple selects like:
<select multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
</select>
<select multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
</select>
<select multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
</select>
and I am looking for best solution. Wanted behaviour is when you select one item in one multi select, then remove it from the others (and conversely).
I using jquery Chosen plugin. Situation: you have 3 roles, but user can be just in one role.
jsFiddle
basically you want to remove the option via JS/jQuery and the update the plugin.
Here is some code
$(".chzn-select").change(function(){
$(".chzn-select")
.not($(this))
.find("option[value="+$(this).val()+"]")
.remove();
$(".chzn-select").trigger("liszt:updated");
});
and a fiddle link JsFiddle
EDIT: try this new fiddle it handles multiple select
$(".chzn-select").css('width', '300px').chosen({
display_selected_options: false,
no_results_text: 'not found',
}).change(function(){
var me = $(this);
$(".chzn-container .search-choice").each(function(){
var text = $('span',this).text();
$(".chzn-select")
.not(me)
.find("option").each(function(){
if ($(this).text() == text) $(this).prop('disabled',true);
});
});
$(".chzn-select").trigger("liszt:updated");
});
EDITED:
try this:
JsFiddle
see if it pleases you... :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With