Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Getting SyntaxError: Invalid regular expression error on a field with an OnChange Client Script

JLaue1
Tera Contributor

Hello - 

I have a string field that I am using for a rate percentage and I am using a Client Script to ensure that the field value has a decimal with 2 numbers to the right of the decimal.  I have done something similar on a catalog variable string field and it works there, but I cannot get it to work on non-catalog form on a custom table.  

Here is my OnChange client script on the effective_tax_rate_st field:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    
    var nbrwn = g_form.getValue('effective_tax_rate_st').replace(/,/g, '.');        
    
    // Check if it is a valid value    
    
    if (isNaN(nbrwn) == true) {
        
        // If not, alert the user and blank the field value
        
        alert("This field must contain a number with maximum 2 decimals separated by a period");        
        g_form.setValue('warehouse_commissions_rate', '');        
    }    
    
    else{
        
        // Set the field value with the number of decimals required        
        
        nbrwn = parseFloat(nbrwn);
        nbrwn = nbrwn.toFixed(2);        
        g_form.setValue('effective_tax_rate_st', nbrwn);        
    }    
}

After putting any type of value in there and then leaving the field, I get the following error:

onChange script error: RangeError: Maximum call stack size exceeded function () { [native code] }

 

Essentially, I am trying to create a 'percentage' field, so if there is a better approach, please advise.

Any help/guidance is appreciated!

Thanks!!

2 REPLIES 2

palanikumar
Giga Sage

Hi,

Since you are using custom table does your field name starts with u_?

Validate the field names with actual field name in custom table

You can also try regex replace(/\,/g, '.')

Thank you,

Palani

Thank you,
Palani

Hello - thanks for your response.  Yes, the field name is correct, it is a field on a custom table, not a custom field on a platform table.  

I'll try the regex change and see if that helps.

Thanks.