Bootstrap-select: No support for disabling options from javascript

Created on 15 Mar 2013  路  7Comments  路  Source: snapappointments/bootstrap-select

Currently there is no way to dynamically disable option from js.

enhancement

All 7 comments

This would be nice to have

There is using JQ and the plugin.

First disable the option with jQuery, and then call render on the plugin.

 $('#mySelect option[value="3"]').prop('disabled', true);
 $('#mySelect').selectpicker('render');

http://jsfiddle.net/PDdn3/2/

but we could simplify this with one call, something like

$('#mySelect').selectpicker('disable', selector);

We could pass the selector as either a straight value, or array of values...

3 or my value or [1,5,10]

and it could also be a JQ Selector..

[value="3"] or #myID or .MyClass

so something like

$('#mySelect').selectpicker('disable', [1,3,'hello']);
$('#mySelect').selectpicker('disable', '[value="3"]');
$('#mySelect').selectpicker('disable', '.MyOptionClass');

?

We could add it in there...but I think it would just be simpler to just run render again. It seems like it would be less documentation to have to remember - simply add your typical line of jQuery to disable the option and then include $('.selectpicker').selectpicker('render'); right after it. What do others think?

It is more flexible leaving it down to the dev to update the data and then re-render. Im inclined to leave it as is.

Not support disabled attribute, but YES support readonly attribute, then...

$("[id^=yourselector]").prop("readonly", "");

Heyy ! I just want to disable some of the options from the drop down list. How can i do that? Please help ! Thanks in Advance

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anton164 picture anton164  路  4Comments

didip picture didip  路  4Comments

yCodeTech picture yCodeTech  路  3Comments

qiyuan4f picture qiyuan4f  路  4Comments

edwolfe807 picture edwolfe807  路  3Comments