Escander
Escander

Reputation: 256

Dojo FilteringSelect - marking specific options in dropdown as disabled (greyed out and not selectable) dynamically

I have a DoJo FilteringSelect created from <select>.

How I can make one (not selected) option as disabled dynamically?

Thanks

UPD: is it possible to REMOVE this element when FilteringSelect was created by PARSE?

Upvotes: 3

Views: 2148

Answers (2)

inanutshellus
inanutshellus

Reputation: 10001

Looks like there's a "disabled" attribute on __SelectOption. When you pass in options, try setting "disabled" to true.

new dijit.form.Select({
    id: 's2',
    options: [
        {label: 'this is disabled', value: 1, disabled:true},
        {label: 'this is enabled', value: 1}
    ]
}

See http://jsfiddle.net/ur87d/

Edit: You said dynamically... So you'll want to use updateOption or removeOption.

dojo.ready(function() {
    var s2 = new dijit.form.Select({
        id: 's2',
        options: [{label: 'one', value: 1},{label: 'two', value: 2}]
    });
    s2.updateOption({label: 'one-updated', value: 1, disabled: true});
    s2.placeAt(dojo.body());
});

See http://jsfiddle.net/ur87d/1/

Upvotes: 2

Chris Li
Chris Li

Reputation: 3725

It's not easy to make option disabled, but it's easy to make it invisible.

Bind your FilterSelect to an ItemFileWriteStore. The options are from items in the store.

You can dynamically add/remove items from the store.

So that your disabled options will not appear in the drop down.

Upvotes: 0

Related Questions