Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable a group while using chosen plugin

What I need is, that if the user selects the option with value 0 disable an entire group in the select, or if i can´t use groups disable all the options i want, it´s possible?

i have try it like this:

$('#ottipo_alcance').chosen().change(function(event){
 if (this.value == '0') 
    $('optgroup option').prop('disabled', true);
 else
    $('optgroup option').prop('disabled', false);                   
  $('#ottipo_alcance').trigger("liszt:updated");
});

<select id="ottipo_alcance" name="ottipo_alcance[]" class="chosen" style="width:200px" multiple="true">
   <option value="0">General</option>
   <optgroup label="Áreas">
        <option value="1">Sistemas</option>
        <option value="2">Operaciones</option>
        ...
   </optgroup>
</select>

NOTE: I also tried with $('#ottipo_alcance').trigger("chosen:updated");

like image 952
meliza_16 Avatar asked Aug 01 '26 11:08

meliza_16


1 Answers

You should be able to disable an entire optgroup by using:

$('#ottipo_alcance').find('optgroup:first').prop('disabled', true);
like image 189
bagonyi Avatar answered Aug 03 '26 04:08

bagonyi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!