Repository navigation
Description
Description
Users sometimes paste an e-mail address, a phone number or an account number with a space at the start or end, and they cannot see it. Input and TextArea save the value as it is. If the field has a pattern that does not allow whitespace, the user gets the pattern error («Feil format eller verdi» by default) on a value that looks right. The backend rejects it too, since the [RegularExpression] that Studio generates from the pattern fails. Without a pattern, the spaces are saved and passed on to whoever receives the form.
I would like an option on Input and TextArea that removes whitespace at the start and end of the value when the user leaves the field. Whitespace inside the value is kept, and nothing changes while the user types.
My suggestion:
- v4: a new property
trimWhitespace,falseby default, so apps that are already published save the same as today. - v9:
trueby default. That is the same split astimeStampon Datepicker, which defaults totruein v4 andfalsein v9.
Two questions:
- Is a property on the component the right place, or would you also like an app-wide setting in
Settings.json? We would turn it on for every Input and TextArea in all our apps. - Do you want it on by default in v9? If so, I can make a PR to altinn-studio after the change is synced over, or you can flip the default when you sync.
Additional Information
Steps with app-frontend 4 from the CDN (30 October 2026), in an app where Innsender.kontaktInfo.epost has "pattern": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$", on a page without validateOnNext:
- Type
ola@example.noand a space in the e-mail field, and leave the field.
=> «Feil format eller verdi» under the field. - Type
90000000with a space before and after in the phone field, which has no pattern, and leave the field.
=> The value is saved with both spaces. - Clear the e-mail field, paste
kari@example.nowith a space before and after, and click «Neste» without leaving the field first.
=> The next page opens, and the value is saved with both spaces./validatereturns theDataAnnotationserror for the pattern on the e-mail field.
27 of our 81 apps in Nordre Follo kommune have a pattern in the data model. For now, we have changed most of our patterns to accept whitespace at the ends, and remove it in the backend when the task ends.
Address has text fields too, but I have left it out for now.
I have a fix with tests and will open a PR that refers to this issue.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity