Automatically clear values in several fields when one field is cleared

Debbi L
Tera Expert

I have a form that, in part, uses four related fields to identify where a piece of hardware is located, and what type it is. I've written a client script that will clear all four fields when one (business_unit) is cleared.

Script Type = onChange

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading) {

          return;

    }

    g_form.setValue('district', '')

    g_form.setValue('area', '')

    g_form.setValue('structure_type', '');

}

This works exactly as it's supposed to. Because you can only query one field in a client script, I've written additional scripts on district, area, and structure_type fields. They mirror the original script, only changing the setValue field names. As you can imagine, once I've done that, it's a race to see which script works (or doesn't).

I receive this error if I activate any of the addition scripts:

onChange script error: RangeError: Maximum call stack size exceeded function (){var o=i(m,arguments);return l.apply(n,o)}

Not much of a surprise, as I should be able to find some way to do this in a single script. Therein lies my challenge - I have no idea where to start. Please help?

Thanks,

Debbi

1 ACCEPTED SOLUTION

I think you might be hitting an infinite loop. Try adding (for each variable you're trying to update in each script):



if(g_form.getValue('business_unit')!=''){


g_form.setValue('business_unit','');


}


View solution in original post

5 REPLIES 5

You're welcome!