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

Nilanjan1
Mega Sage

@gunishi  I understand that the value which drives the subvalues is a checkbox? are the other sub-values also a checkbox or these are dropdowns?

Where are you actually putting these information is it in a catalogue form or any other form? 

 

Regards,

Hi @Nilanjan1 

 

The other values that are filled in (like onion/lettuce) are checkboxes. The bread is a value in a multichoice. 

 

The problem I have found is the oldValue is the value of the bread when the page loads, not the dynamic value if the user changes their mind. 

 

How would I go about finding this?

 

Kind regards, 

G

@gunishi 

 

I have created a variable which says "Type of Bread" and have set one of the values as none and everytime the form loads it is set to -- None --. screenshot attached, 

 

Nilanjan1_0-1697216666984.png

 

Please check the script as well if it works.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    if (g_form.getValue('type_of_bread') == 'cornbread') {
        g_form.setValue('onion', 'true');
        g_form.setValue('lettuce', 'true');
    }
	if (g_form.getValue('type_of_bread') !== 'cornbread'){
		g_form.clearValue('onion',false);
		g_form.clearValue('lettuce',false);
	}
    //Type appropriate comment here, and begin script below

}