How to clear a value ready to be picked again on CI?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 08:27 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 08:35 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 08:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 08:48 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-12-2023 08:52 AM
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