Disable and enable Selectize Dropdown based on CheckBox

I am trying to enable and disable Selectize Dropdown depending on Checkbox value. I wrote something that only works for disabling the control. But I cant enable it.

Here is what I tried:

enter image description here

It shows this error:

enter image description here

if I comment out $('#' + Id)[0].selectize.enable(); this line then disabled functionality works just fine.

Is a work-around available?

Upvotes: 0

Views: 307

Answers (1)

I had to check if $('#' + Id)[0].selectize has value or not. This solved my issue. Here is full snippet for everyone:

function EnableDisablePicker(Instrution, Id) {

    if (Instrution === 'Disable') {

        if ($('#' + Id)[0].selectize) {
            $('#' + Id)[0].selectize.disable();
        }
    }
    if (Instrution === 'Enable') {
        if ($('#' + Id)[0].selectize) {
            $('#' + Id)[0].selectize.enable();
            $('#' + Id)[0].selectize.clear();
        }
    }

}

Upvotes: 0

Related Questions