Number field formatting with commas and parentheses

Number field formatting with commas and parentheses

CT General AssemblyCT General Assembly Posts: 20Questions: 3Answers: 1

We have number fields that we are allowing inline editing of. The render we are using is as follows:
render: $.fn.dataTable.render.number(',', '.', 0, '')
If the user types 100,200 for some reason, the number is truncated down to 100.

Also, we want them to be able to type(1000) and have that be equal to -1000.

Any suggestions?

Replies

  • Bindrid2Bindrid2 Posts: 79Questions: 4Answers: 12

    I am wondering if the problem is elsewhere. I am using it up to a billion with no issue.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    If the user types 100,200 for some reason, the number is truncated down to 100.

    That is correct and expected for that rendering function. It expects the number to be passed in as a "real" number, not a formatted one (i.e. one which Javascript understands as a number - with a dot decimal place).

    You would need a custom renderer to do what you are looking for here, and also for the negatives (allow either to be input, output only one style).

    Allan

  • CT General AssemblyCT General Assembly Posts: 20Questions: 3Answers: 1

    In retrospect, I took a different approach. In the preSubmit, I'm converting the formatted number back to a "real" number. This seems to do the trick. Thanks for the replies. Just thinking about it after I read them allowed me to take a new route and now it is working as I hoped.

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Lol, so mine worked accidently because I created a field type plug-in that returns a real number.

This discussion has been closed.