Skip to main content
shobhits0002
September 7, 2022
Solved

I have a requirement where in a text field needs to be formatted in a specified format of "X.1234567"

  • September 7, 2022
  • 5 replies
  • 0 views

I have a requirement where in a text field needs to be formatted in a specified format of "X.1234567", where 'X' and '.' will be a constant followed by 7 digits.
If we are typing 123 in the text field, it should be formatted to "X.0000123". 

Any help would be appreciated.

Thanks!

    Best answer by mikes0011

    Try this - it doesn't even allow the user to enter anything that would throw a validation error (as far as i can tell), as it automatically reformats any number or text entered into the desired result.  It also (by brute force) caps the length of the number following "X." to 7 total digits.  You may need to adjust slightly, depending on the particular behavior you want.

    a!textField(
      value: local!text,
      saveInto: {
        a!save(
          local!text,
          left(
            "X." & text(
              todecimal(cleanwith(save!value, "0123456789")),
              "0000000"
            ),
            9
          )
        )
      }
    )

    5 replies

    mikes0011
    Brainy
    September 7, 2022

    What will the user standardly be expected to type? What range of allowed input will there be?  Is the text following "X." only ever going to be essentially an integer?

    Will the formatted value of "X.0000001" etc be for display purposes only or would we want the *actual stored* value to reflect that text as well?

    The Expression Guru
    shobhits0002
    September 7, 2022

    Users may type any characters or numbers then that should be taken care with validation messages, but when numbers are entered, it should be formatted as "X.seven digits",
    scenario1 : If user has entered 123 in the fiels, then formatting should make the field value as "X.0000123"
    scenario 2: If user has entered 1234567, the formatting should make the field value as "X.1234567"
    Anything apart from this, should throw validation error.

    shobhits0002
    September 7, 2022

    Also, Will the formatted value of "X.0000001" etc be for display purposes only or would we want the *actual stored* value to reflect that text as well? ---> Formatted value should be for display in the text field and separately this has already been taken care at back end as we are using external database.