Eliminate Leading and Trailing Spaces in Fields - Catalog Client Script

alexcharleswort
Tera Expert

Hi all,

I have a need to eliminate leading and following spaces in a field on a catalog item. I can get this to work nicely as a business rule for a table, but I would like to utilize this as a catalog client script on a form.

My string variable name is thirdparty_whofirst

I have tried an onSubmit catalog client script like this and it doesn't seem to work:

function onSubmit() {

    //Type appropriate comment here, and begin script below

  var first = g_form.getValue('thirdparty_whofirst');

  g_form.setValue(first, first.toString().trim());

   

}

Let me know if you guys know where I'm and going wrong.

As always, thanks in advance for your help.

1 ACCEPTED SOLUTION

Whoops, you don't have your field name as the first parameter of setValue...Should have caught that...



Try



g_form.setValue('thirdparty_whofirst', first.trim());  


View solution in original post

12 REPLIES 12

Alikutty A
Tera Sage

Please try if this works



function onSubmit() {  


    //Type appropriate comment here, and begin script below  


  var first = g_form.getValue('thirdparty_whofirst');  


  first = first.replace(/^\s+|\s+$/g, "");


  g_form.setValue("first", first);  


}  



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response


Will that script get rid of all spaces in the field? I dont want to get rid of all spaces, just any leading or following ones.


Leading and trailing spaces only, It is regular expression.



Just make sure you are setting it on the right field name. In your code the first just looked like a variable and not field name.



Thanks


Please Hit like, Helpful or Correct depending on the impact of the response