cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Forms - Display numeric fields with thousands separators

Jump to solution

I don't seem to be able display a number (on edit, or on view) with comma separators for thousands etc. I tried using currency type, but then I can't get rid of the dollar ($) symbol.

Is there a way to do this out of the box?

Tags (1)
0 Kudos
Reply
13 Replies
Workflow Hero

Re: Forms - Display numeric fields with thousands separators

Jump to solution

Hi Joanne,

something similar has been discussed before in this thread: How to add thousand separators to integer fields in a repeating section 

Unfortunately the code provided doesn't work out of the box as you will have to add the "NWF" in front of each "$"-selector.

Just take this corrected code and put it into your Form Settings -> Custom Javascript section:

function commaSeparateNumber(val){
     if (!val){
          return 0;
     }
     while (/(\d+)(\d{3})/.test(val.toString())) {
          val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
     }
     return val;
}
function doNumberFormat(){
     NWF$('.numbers .ms-rtestate-field').each(
          function(index,element){
               NWF$(this).html(commaSeparateNumber(NWF$(this).html()));
          });
     NWF$('.numbers .nf-calculation-control').each(
          function(index,element){
               NWF$(this).html(commaSeparateNumber(NWF$(this).html()));
          });
}

setTimeout(doNumberFormat, 5000);

As described in the post above you can change the number in the "setTimeout" function to let the seperators appear faster after page load.

Still wondering why Forms designer doesn't offer numeric formatting by default!

Best Regards

Philipp

Reply
Workflow Hero

Re: Forms - Display numeric fields with thousands separators

Jump to solution

good catch there Philipp...the $ thing works on my pages because I always load a different version of Jquery than the one shipped with Nintex and call noconflict().

my bad...i didnt realise this while writing the answer

Reply
Workflow Hero

Re: Forms - Display numeric fields with thousands separators

Jump to solution

Thanks Philipp. Where do I call the function from? I've called javascript from the validation section of the control previously, however i imagine that is not the location for this particular issue. 

0 Kudos
Reply
Workflow Hero

Re: Forms - Display numeric fields with thousands separators

Jump to solution

worked it out from another post. include 'numbers' as the CSS class in the control. Thanks Phillip. This works great. 

0 Kudos
Reply
Workflow Hero

Re: Forms - Display numeric fields with thousands separators

Jump to solution

Hi all

I did all of these steps, but I couldn't be able to run the function correctly! 

I just copied the code and paste it in custom JS section in my form and after that I set fields that exist for my field as a below picture

What's my wrong?

--------------------

Regards

Amir

0 Kudos
Reply
Workflow Hero

Re: Forms - Display numeric fields with thousands separators

Jump to solution

Hi

any body there for helping me?

0 Kudos
Reply
Workflow Hero

Re: Forms - Display numeric fields with thousands separators

Jump to solution

Hi Amir,

can you open your browsers developer tools, refresh your forms page and have a look in the console if any errors are thrown?

To see if your JS code actually gets applied you can also insert a "console.log('Hello World')"  at line 10 of the code and check if this is logged to the console. If it doesn't appear in the console, the code isn't applied at all and we may need to dig a little deeper.

Cheers

Philipp

0 Kudos
Reply
Workflow Hero

Re: Forms - Display numeric fields with thousands separators

Jump to solution

Hi Philipp

Sorry for my delay.

I tested your solution, I saw the message in the console, but still I can't run this code in my form! 

I only want to add thousands separator to one singleline field! 

Could you help me?

I changed some parts of your code for fitting my form, but it doesn't work

function commaSeparateNumber(val){

if (!val){
return 0;
}
while (/(\d+)(\d{3})/.test(val.toString())) {
val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
}
alert(val);
return val;
}
function doNumberFormat(){

NWF$('.numbers').each(
function(index,element){

NWF$(this).html(commaSeparateNumber(NWF$(this).html()));
});
}

setTimeout(doNumberFormat, 1000);

Regards

Amir

0 Kudos
Reply
Workflow Hero

Re: Forms - Display numeric fields with thousands separators

Jump to solution

Hi Amir,

after copying your code directly i received an error in the browser console that was caused by wrong formatting. Bur basically your code is working. Try to take this one:

function commaSeparateNumber(val){

     if (!val){
          return 0;
     }
     while (/(\d+)(\d{3})/.test(val.toString())) {
          val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
     }

     return val;
}
function doNumberFormat(){
     console.log("entered doNumberFormat")
     NWF$('.numbers').each(
          function(index,element){
               NWF$(this).html(commaSeparateNumber(NWF$(this).html()));
          });
}setTimeout(doNumberFormat, 1000);

Just copy it from the forum and paste it directly into your custom js section. Maybe Nintex just couldn't read your code at one point.

Keep us updated!

Cheers

Philipp

Reply