Page 1 of 1

field formatting after AJAX request

Posted: Thu Apr 21, 2016 3:19 pm
by kswisher
I have a process that is calling out to another AJAX process to do a bunch of calculations, which takes the result of that and updates the text boxes on the screen using the pui.set() API.

The only issue I am having is that the fields lose all of their formatting after this. I have the fields setup to be displayed as number, with the Use 1000 Separator checked. So before the call, it will display as 100,000.00 and after I run my pui.set() i get 100000.00.

Do I need to run some sort of applyProperty() on each field to reset that formatting?

Re: field formatting after AJAX request

Posted: Fri Apr 22, 2016 4:17 am
by Scott Klement
pui.set() does not re-format the number, it uses whatever format you've given. So you'll want to preformat it before calling pui.set().

An easy way to do that if you are using a modern, up-to-date, browser is like this:

Code: Select all

pui.set("yourField", Number(100000).toFixed(2).toLocaleString());
toFixed(2) formats it with 2 decimal places
toLocaleString() adds commas or periods as decimal separators, based on the browser's locale settings.

toLocaleString() does require an up-to-date browser. It will not work on IE10, for example. There is more information here:
https://developer.mozilla.org/en-US/doc ... caleString

Of course, you can use any sort of string/number operations you like to do the formatting. Google number formatting in JavaScript for lots of examples... toLocaleString() is just an example that works nicely for me.