How to clear a value ready to be picked again on CI?

gunishi
Tera Guru

Hi there, 

 

I have a requirement where I have a number of checkboxes on a CI. If a user picks cornbread, it automatically selects onion, lettuce etc, and each different bread has a specific sandwich combination. 

 

I have been able to set these values. but not sure how to clear them. 

 

I tried:

 

if (oldValue == 'cornbread'){

    g_form.clearValue('onion');

}

 

but this is not working. I had initially tried:

 

if (newValue !='cornbread'){

    g_form.clearValue('onion');

}

 

However, this just clears the onion choice for anything that isn't cornbread, so if a user selects a bread that also onion in it, this overrides the 'setValue' and clears it on selection. 

 

Any help with this matter would be much appreciated. 

 

Kind regards, 

G

7 REPLIES 7

Anand Kumar P
Giga Patron
Giga Patron

Hi @gunishi ,

Use below script and change as per your requirement

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    if (newValue === 'cornbread') {
        g_form.setValue('onion', 'true');
        g_form.setValue('lettuce', 'true');
    } else if (oldValue === 'cornbread') {
        g_form.clearValue('onion');
        g_form.clearValue('lettuce');
    }
}

Please mark it helpful and solution proposed if it is helpful.

Thanks,

Anand

Hi @Anand Kumar P 

 

I have implemented this but the choices do not clear with this syntax. Do you have any pointers as to where I could go from here, or anything else I could try?

 

Kind regards, 

G

Hi @gunishi ,

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    if (newValue === 'cornbread') {
        g_form.setValue('onion', 'true');
        g_form.setValue('lettuce', 'true');
    } else if (oldValue === 'cornbread') {
        g_form.setValue('onion', '');
        g_form.setValue('lettuce', ''); 
    }
}


Try above one.

Thanks,

Anand 

Hi @Anand Kumar P 

 

Thanks for trying again. For some reason this is also not working. I have a feeling the oldValue part is what is causing the issue so I will investigate further, but so far very confused. 

 

Kind regards, 

G