The CreatorCon Call for Content is officially open! Get started here.

How do I remove spaces from start and end of catalog item string variable?

swnewton
Mega Guru

Greetings,

I'm trying to write an onChange catalog client script to check a string variable for beginning and trailing spaces.  If found, give the user an error message and set the value to null.  Everything I've tried hasn't worked.  Does anyone have the code to accomplish this?

Thanks in advance!

-Skip

1 ACCEPTED SOLUTION

Steven Slocum
Tera Guru

I haven't tried this, but maybe use the 'trim' method. If you go this route, it would likely be better as an On Submit Client Script, otherwise it would run and run since you are setting the value on the same variable causing the on-change to run.

 

 
        var str = g_form.getValue('variable_1');
        var wsr = str.trim();
        g_form.setValue('variable_1',wsr );
    

View solution in original post

2 REPLIES 2

Steven Slocum
Tera Guru

I haven't tried this, but maybe use the 'trim' method. If you go this route, it would likely be better as an On Submit Client Script, otherwise it would run and run since you are setting the value on the same variable causing the on-change to run.

 

 
        var str = g_form.getValue('variable_1');
        var wsr = str.trim();
        g_form.setValue('variable_1',wsr );
    

swnewton
Mega Guru

That worked...thanks!