346
Views
2
Comments
Solved
How to format text in a specific way in input control?
Application Type
Reactive
Service Studio Version
11.53.20 (Build 61431)

I have a text attribute that accepts no more than 11 characters. I have validation in place to ensure the accepted text is exactly 11 characters (no more, no less) and that all the characters are numeric. However, when users are inputting this text, it would be helpful if my input control formatted their input. Here are a few examples of what I am needing:

  1. User types "12123123456", but as they type it in the control, it auto-formats to "12-123-123456". The former value, "12123123456" is what is saved to the database.
  2. User types "12-123-123456", and what they see as they type it in the control is also "12-123-123456". What is saved to the database is "12123123456".

The control is simply an "input" widget, which, matching the database attribute restriction, has a Max. Length property of 11 (thus preventing a user from, say, typing in the input seen in my second example). I have seen this Forge component, but I am wanting to verify that there really is no other way to achieve this without an extra asset. If this sort of behavior does require a Forge component, I am open to additional recommendations.

Thank you!

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Jared,

There is no other way to format input while the user types than using either a Forge asset or creating something yourself using JavaScript. Standard web technologies have no provision for masked input, unfortunately.

2023-02-09 17-26-57
JD136

Thanks for confirming. I ended up using InputMask React: https://www.outsystems.com/forge/component-documentation/7838/inputmask-react/0.

The only inelegant aspect of the solution is that my input control needs to have a specified Max. Length of 13, while the underlying database attribute I'm keeping to 11. I used a MaskPattern of "9{2}\-9{3}\-9{6}" to achieve the result seen in my question.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.