Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

onChange client script on 2 different fields interact with each other causing an error

Dave65
Tera Contributor

Thanks in advance for your help!

I have 2 fields one takes a percentage of the base pay for an increase and the other takes a dollar amount of the increase.

We want the user to be able to fill one of the fields in and the onChange script will make the calculation to fill in the other.

The problem that I'm having is that if both scripts are Active, they trigger each other and then I get the following error:
onChange script error: SyntaxError: Invalid regular expression: /(^|[\x20\t\r\n\f])form-field([\x20\t\r\n\f]|$)/: Stack overflow function () { [native code] }

The information I've been able to find indicates that I'm running into Recursion. The suggested solution was to add newValue === oldValue as follows:

 if (isLoading || newValue === '' || newValue === oldValue) {
              return;
}
 
I've done that and it doesn't work. I even tried it with == instead.
 
I'd appreciate any suggestions.
 
Thanks!
 
Dave
1 ACCEPTED SOLUTION

Brad Bowman
Mega Patron

Post both scripts for more insight, but it seems like you should do something like:

if (g_form.getValue('the other field') != the_value_to_be_set) {
    g_form.setValue('the other field', the_value_to_be_set;
}

In this way the 'other field' will not be updated if the value is already what you're about to set it to, which if done in both scripts would head-off the recursion.

View solution in original post

2 REPLIES 2

Brad Bowman
Mega Patron

Post both scripts for more insight, but it seems like you should do something like:

if (g_form.getValue('the other field') != the_value_to_be_set) {
    g_form.setValue('the other field', the_value_to_be_set;
}

In this way the 'other field' will not be updated if the value is already what you're about to set it to, which if done in both scripts would head-off the recursion.

Thanks Brad!
Worked like a charm!
Now I'm kicking myself for not thinking of it 😁

 

Dave