Skip to content

Option to remove whitespace at the start and end of Input and TextArea values #4402

Open

Description

@Bjarnisan

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, false by default, so apps that are already published save the same as today.
  • v9: true by default. That is the same split as timeStamp on Datepicker, which defaults to true in v4 and false in 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:

  1. Type ola@example.no and a space in the e-mail field, and leave the field.
    => «Feil format eller verdi» under the field.
  2. Type 90000000 with a space before and after in the phone field, which has no pattern, and leave the field.
    => The value is saved with both spaces.
  3. Clear the e-mail field, paste kari@example.no with 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. /validate returns the DataAnnotations error for the pattern on the e-mail field.
Image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions