简体   繁体   中英

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:

在此处输入图像描述

It shows this error:

在此处输入图像描述

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

Is a work-around available?

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();
        }
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM