Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#813833
Hi Team,
I have a Grid, named as Grid1. In this Grid, I have an Amount text field, named as Amount.
I would want to ensure, that whenever a user enters an amount, it is in 2 decimal points. If they enter a whole number, eg. 50 , then it converts by itself and shows 50.00

Please assist :)
#813837
Hello,

You can get the result you described by using jquery to transform the value of the Amount text field everytime a new row is added to the grid, supposing you have a grid like this:

Image

You can add the following code to the javascript of the dynaform:
Code: Select all
jQuery("#gridVar001").onAddRow(
  function(row, grid, index)
  {
    var previous =   $("#gridVar001").getValue(index-1, 4);
    var p_value = parseFloat(previous);
    $("#gridVar001").setValue(p_value.toFixed(2), index-1, 4);
});
How the code works:
When a new row is added to the grid, the "index" parameter in the function points to the newly created row, we need to alter the value of the previous row so index-1 is used.
4 points to the # of column we are trying to alter, typically in arrays the first value is 0, but when working with grids in PM the first value is 1, thats why the number of the column "decimal value" is 4 and not 3
Notice that with this code every-time a new row is added, the value of "decimal value" in the previous row is changed, this means that an extra empty row must be added at the end before submitting the form, otherwise the last row will remain unchanged.
If you need decimals with more than 2 decimal points change .toFixed(2) to your desired number of decimals, for example if you want 100.0005 you would need to change it to .toFixed(4).
#813859
Unfortunately, grids dont have an onChange event in PM, however, if you dont mind the change to be done all at once at submit you can use onSubmit, that way when the user clicks on the submit button all the Amount controls in your grid will be transformed to decimal right before the form is submitted.

Here is an example code:
Code: Select all
$("#1681428115abb8944b19c29088403369").setOnSubmit(function(){
  if ($("#gridVar001").getNumberRows()!== 0) 
  {
      for (var i = 1; i <= $("#gridVar001").getNumberRows(); i++) 
      {
         var actual =   $("#gridVar001").getValue(i, 4);
         var valor = parseFloat(actual);
         $("#gridVar001").setValue(valor.toFixed(2), i, 4);
   	  }
  }
  else 
  {
      alert("There are no records, add at least one row.");
      return false;
  }
});
Notice you have to use your own form ID at the first line, if you don't know how to get it let me know and i will provide an screen-shot of where to find it

Also, the first if is used to make sure the user is submitting at least one row, if no rows are present in the grid the message "There are no records, add at least one row" will appear and "return false;" statement will prevent the form from being submitted; if you wish you can remove that part and only use the for loop.
#813931
This might be happening because in this piece of the code:
Code: Select all
var actual =   $("#gridVar001").getValue(i, 4);
var valor = parseFloat(actual);
$("#gridVar001").setValue(valor.toFixed(2), i, 4);
I use 4 because on my grid the amount text field is the fourth column, you have to replace the 4 with the number of column you are using for your amount text field
#813967
Thanks.
Yes I had changed the 4 to 5. However, when I want to preview the form, it just keeps Loading. Below is the codes, I have commented out my onAddRow code, this code worked on my form.

//jQuery("#gridVar001").onAddRow(
// function(row, grid, index)
// {
// var previous = $("#gridVar001").getValue(index-1, 5);
// var p_value = parseFloat(previous);
// $("#gridVar001").setValue(p_value.toFixed(2), index-1, 5);
//});


$("#89981079158a3c1005bfaa0068976190").setOnSubmit(function(){
if ($("#gridVar001").getNumberRows()!== 0)
{
for (var i = 1; i <= $("#gridVar001").getNumberRows(); i++)
{
var actual = $("#gridVar001").getValue(i, 5);
var valor = parseFloat(actual);
$("#gridVar001").setValue(valor.toFixed(2), i, 5);
}
}
else
{
alert("There are no records, add at least one row.");
return false;
}
});
#813971
I tested out your code and there doesnt seem to be any problems, have you tried running a test case, and if so, did you get any errors in there as well?

To help you further I would need to check your dynaform and see exactly what problems you are having, could you export your dynaform and attach the file in your next reply?
#813991
I checked your code, you have two errors on line 61 and line 108 of your javascript, the id of your form is incorrect, it should be "8166665025ace0a34c4b977078089638" like this:
Code: Select all
getFormById("8166665025ace0a34c4b977078089638").setOnSubmit(function() {
and
Code: Select all
$("#8166665025ace0a34c4b977078089638").setOnSubmit(function(){
#814023
Oh sorry, you are right, that is perfectly possible.

But in any case, thats the only error i found in your code, its the only thing i changed and it works on my PM (what version are you using by the way? im on 3.2.2), I would advise you to check your javascript and double check if the id you wrote matches your form id in both lines.

Image

Being the best in the started business is the obje[…]

Winzo is a popular and unique game on the mobile p[…]

Cannot create process using templets

Real details. The problem was solved by effect!

However, it is essential to use it responsibly and[…]