Solved

How to add thousand separators to integer fields in a repeating section

  • 29 November 2016
  • 4 replies
  • 165 views

Hi,

 

I have a form with a repeating section where there are several fields with the integer data type. I want to use thousand separators in those fields, but have not figured out how. Is it possible?

 

Thanks!

Lisa

icon

Best answer by amolvaidya 6 December 2016, 02:39

View original

4 replies

Badge +5

for all integer fields assign a css class (this is just for selection sake, you need not actually have that css class). lets say our class is "numbers"

include an external js file to your nintex form or add below code to custom javascript for the form

//Function to do the comma magic

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;
}

//pick each ".numbers" element and do the comma thing

function doNumberFormat()
{

  //Handles single line text boxes in view mode
  $('.numbers .ms-rtestate-field').each(
  function(index,element){
    $(this).html(commaSeparateNumber($(this).html()));
  });

  //Handles calculated value in view mode
  $('.numbers .nf-calculation-control').each(
  function(index,element){
    $(this).html(commaSeparateNumber($(this).html()));
  });
}

//Call the formatter function after loading the page

setTimeout(doNumberFormat, 5000);

explanation for above code

commaSeparateNumber - will format text with thousand seperator

doNumberFormat - will iterate through each control where css class is set to "numbers". Within that set it will then find controls with css class "ms-rtestate-field". It will then pass the html contents of current control to the commaSeparateNumber function to get back formatted text and replace html.

same for "nf-calculation-control"

 

the last line setTimeout will call the format function after 5 seconds of page load. Adjust this time according to your page.

Edit (Philipp Lucas): See this post for corrected code -  

Userlevel 7
Badge +17

Lisa Morgan‌ are you using Nintex Forms or Infopath? Where do you want to display the number formatted properly? In the form itself or in the list item display form?

I guess in Nintex Forms you can set field formatting the same way as in Infopath - so you can set data type to "decimal" (or number) and then in formatting set a proper mask when a value is displayed:

Regards,

Tomasz

Userlevel 7
Badge +17

Hi!

Have you found a solution for your question? Or do you find any from the answers as "Correct" so that you can mark it accordingly?

Best regards,

Tomasz

Badge +2
Is this available on Nintex 2013 as well? Cannot find that option in TextBox.

Reply