Prevent line break in multi line text field

gnunez
Kilo Guru

Hello all,

Does anyone know if theres a way to prevent line breaks in a multi line text field?

We have an integration with DocuSign so when the user submits the form it got the error "String contains control character". When comparing to other forms the user had used enter for a new line which caused the issue. If the user just types away and goes onto the second line it was fine.

I want to see if theres a way to prevent the user from clicking enter or if theres a way to remove the line break after the form has been submitted.

Any assistance with this would be greatly appreciated!

Thanks in advance,

Grace 

1 ACCEPTED SOLUTION

Hi Grace,

Please replace trim() for this:

 

replace(/\r?\n|\r/g, "");

 

Example:

var str = "test 1\n"+
" test2\n"+
" test 3";
str = str.replace(/\r?\n|\r/g, "");

 

Result: test 1 test2 test 3

 

Regards,

Pedro Lopez

View solution in original post

12 REPLIES 12

Hi Grace,

I will recommend to do it onSubmit. It means, the script will run once you submit the record and you can make the validation. Try this:

OnSubmit:

var descriptionOldValue = g_form.getValue('description');
var descriptionNewValue = descriptionOldValue.trim();

g_form.setValue('description', descriptionNewValue);

 

Hope this helps,

Pedro Lopez

Hi Pedro,

 

I tested with your suggested code but the line break is still there.

I also have another field "request_purpose" that has the same requirement and tried with that as well but still no luck. šŸ˜ž

 

Thanks,

Grace

Hi Grace,

Can you add an alert at the end of your code, please? And Can you share here the response, please? It is working in my side, I just want to know how you are doing it.

 

//add this alert

alert(descriptionNewValue);

 

Regards,

Pedro Lopez

Hmm then I'm probably not doing something right.

After adding the alert this is what I got when submitting and after I select ok the form submits:

find_real_file.png

 

Heres the catalog client script:

 

Hi Grace,

Can you tell me what is the expected behavior, please? The code seems to be working. The code will remove the extra lines (white spaces). Example:

String: "    My testing   ";

Result: "My testing";

 

Can you explain more in details the expected result you would like to see, please?

 

Regards,

Pedro Lopez