Hoppa till huvudinnehållet

Prevent formatting of numbers when displayed in a textbox

Kommentarer

12 kommentarer

  • Stefan Schweigert

    Hello Jostein,

     

    When you enter a value into a Text Box element, the element assumes that the value entered will correspond to text. You can use the Parse Number activity to access the input value as a number after the form is submitted.

     

    I believe the formatting of the input value is controlled based on your region settings within the browser. How are you populating the Text Box with this value?

     

    Thanks, Stefan

    0
  • Jostein Svegården

    Ok, but I don't want the number to be formatted with a thousands separator when displayed as text. Is that behavior configurable? Or do I have to use a Number form element instead of a Text Box?

    0
  • Jostein Svegården

    As far as I can see, Parse Number is not able to parse "3 456" into the number 3456?

    0
  • Stefan Schweigert

    Hi Jostein,

     

    I'm interested in knowing what your process is for populating the Text Box, and what your system and browser language settings are so that I can try to reproduce this issue.

    0
  • Jostein Svegården

    Client side or server side?

    0
  • Stefan Schweigert

    I'm mostly interesting in client-side, but the server-side info would be useful as well.

    0
  • Jostein Svegården

    Client side is Norwegian.

     

    I am sending =$form1.state.textBox1.value (containing "3 456") into a Parse Number with ID number1, and use =$number1.result as the attribute value in Set Feature Attribute. What I see when writing the feature.toJson() to the log is that the value is NaN.

    0
  • Stefan Schweigert

    I've been able to reproduce the behaviour you mentioned and its because of the client Language settings and how we display the number inside of an element that expects text. Using a Number form element prevents this issue, since outside of the form you'd access the actual value rather than the displayed value: =$form1.state.number1.value.numeric

    0
  • Jostein Svegården

    Thanks, I'll try that, but it is some work involved in changing from textbox to numeric. But with a text box, how do I avoid the displayed value being formatted with a thousands separator? We don't usually do that in Norwegian

    0
  • Stefan Schweigert

    It shouldn't appear within the Number. My example used a ',' as a thousands separator but in the form element it appears without it.

    0
  • Jostein Svegården

    So conclusion is: Use Number for numbers, not TextBox?

    0
  • Stefan Schweigert

    When you are expecting a Number as input, then that holds true. A Text Box is intended to be used for String inputs. You can use the Text Box, but you might need to do some input/output sanitization of the values.

    0

Du måste logga in om du vill lämna en kommentar.