← Back to team overview

dhis2-users team mailing list archive

Creating a thousand Separator on a custom form field

 

Hello

I am starting to use DHIS2 so far its a great tool but quite dificult to
understand out of the box, Right now i am trying to make a thousand
separator for a number field, i have a small dataset with just one data
element and i want to make it write thousand separators as you type so
instead of typing 10000 i will get 10.000 and so on.

I know i have to use a custom form for this and do some javascript, however
i cant get the right code to work. Tried something like this (i am no
programmer just trying to pull this on my own):



















*<script type="text/javascript">onFormLoad( addCommas(nStr) {    nStr +=
'';    x = nStr.split('.');    x1 = x[0];    x2 = x.length > 1 ? '.' + x[1]
: '';    var rgx = /(\d+)(\d{3})/;    while (rgx.test(x1)) {        x1 =
x1.replace(rgx, '$1' + ',' + '$2');    }    return x1 + x2;}
);</script><p>    VENTAS FORMALES:</p><p>    <input
id="DaFSlVuAjt9-mmVJla5Q8NB-val" maxlength="20" name="Ventas Formales"
onchange="return addCommas(this.value)" style="width:7em;text-align:center"
title="DaFSlVuAjt9 - PL - Ventas Formales - mmVJla5Q8NB - (default) - int"
type="text" /></p>*

The original code was taken from here:
http://stackoverflow.com/questions/9773689/how-do-i-add-thousands-separator-to-my-html-form
I cant make this work, maybe someone has something that actually works. Any
ideas are appreciated, thank you.
-- 


*Patricio López Salgado*