Automatically trim whitespace from input

Hello.
How do I make appsheet automatically trim whitespace from the beginning and end string of an Input Form text field?

Solved Solved
0 12 3,577
  • UX
1 ACCEPTED SOLUTION

You can do that with an Event Action if you set that action from your Form View.

View solution in original post

12 REPLIES 12

There is a TRIM() function though there isnโ€™t yet a support article for it.

@Steve

So how / which constraint would I use TRIM? I want any text that a user inputs to a form to automatically be trimmed for whitespace when the form is being saved.

You can do that with an Event Action if you set that action from your Form View.

Im checking out your suggestion now, but didnt appsheet used to do this?

Let me check this internallyโ€ฆ

Thanks Aleksi!

Just to let you know how I use this: My app tracks the last time a user has updated any info in a record. I dont want them to be able to add a few blank spaces in a field and trick the app into thinking a material change in data has been made.

@David_Joyce I played with this one a little and it seems to filter whitespaces from the end and from the beginning, but not from the middle. If you add one or more spaces but without any real letter or number, it filters all away and then the fieldโ€™s value is blank and it should not show that field in the detail view.

As @Aleski has pointed out, TRIM() does not filter whitespace from the middle of the text. Based on your concern of adding spaces to โ€œtrickโ€ the app into thinking there was a change, youโ€™ll want to keep that in mind.


As for trimming the whitespace, there are a few options:

Trimming Whitespace on Input:

  • Use validation to determine if there is beginning or ending spaces and if so, make field invalid and show a message that leading and trailing spaces are not allowed. I.e. force the user to enter it correctly.

  • Use two columns. One for input only and second for the internal app usage that trims spaces.

Trimming Whitespace After Save:

  • As @Aleski pointed out, you could attach an action to the Form Save that trims the spaces to the input column.
  • This is probably not for your use case, but in case others are interestedโ€ฆIf for any reason you need to retain the raw input, you can use the TRIM() function anywhere else within the app for that column. Believe it or not there are cases where this applies, e.g. spaces inserted for alignment purposes but the value with spaces and the values without spaces are to be treated the same.

TRIM() does filter extra whitespaces from the middle. That was the whole idea for the TRIM() expression in the beginning.

Thank you for the correction! I do see now that multiple entered spaces in the middle are trimmed to just single one. Leading and trailing spaces are removed entirely!

Example of TRIM()
2X_f_ff82cf2fe3f6629c4791126ee42344c12e2833d8.png

Trimming whitespace from the end and the beginning is acceptable. If field only contains whitespace, then the behaviour I need is to set it to blank. So far so good

As to my users putting whitespace in the middle of real text, Iโ€™ll accept that because there is no way I can see of preventing that.

Good solution @Aleksi, and thanks @WillowMobileSystems

EDIT: Just read your post about TRIM removing extra whitespace from the middle. Excellent!!

Yes you can filter extra whitespaces with an Event Action using TRIM() when the form is saved.

Top Labels in this Space