Questions and discussion about using ProcessMaker: user interface, running cases & functionality
#812558
Hi,

I have a problem (probably really simple ;) )
I have a checkgroup "checkgroup1" with three values 1, 2, 3
I want to check what values were selected: 1 , 1 and 2, 2 and 3, etc. with the option getValue() and do some math that depends on the checkgroup selection.

Unfortunately I can't get value when more than one option from checkgroup1 is selected:

function checkgroup_math()
{
if ($("#checkgroup1").getValue() == "1"){
function do_math(){
...
...
...
}
do_math();
}
else { }
$("#checkgroup1").setOnchange(checkgroup_math);

How to: if ($("#checkgroup1").getValue() == value 1 and value 2, etc. )


By the way.. Is it better to use getValue or setOnchange( function(newVal, oldVal)?

Thanks for help
Regards,
#812563
Your code would be something like this:
Code: Select all
function checkgroup_math(aSelected, aOldSelected) {
   if ($.inArray("1", aSelected) != -1 && $.inArray("2", aSelected) != -1) {
          do_math()
   }
}
$("#checkgroup1")setOnchange(checkgroup_math);      //when checkgroup changes
checkgroup_math($("#checkgroup1").getValue(), []);  //when DynaForm loads
#812569
After a few tweaks everything works like a charm :)

Below my if statements:

Option 1 selected in checkgroup
if ($.inArray("1", aSelected) != -1 && $.inArray("2", aSelected) != 0 && $.inArray("3", aSelected) != 0 )

Option 1 and 2 selected in checkgroup
if ($.inArray("1", aSelected) != -1 && $.inArray("2", aSelected) != -1 && $.inArray("3", aSelected) != 0 )
.
.
.
etc.

Thanks for help !
#812571
You are probably going to have problems with your code, because $.inArray() returns the array position of the searched item, so it can be 0, 1, 2, 3, etc. or -1 if not found.

If you want to check if option "1" is selected in the checkgroup, use this code:
if ($.inArray("1", aSelected) != -1)

To check if options "1" and "2" are selected:
if ($.inArray("1", aSelected) != -1 && $.inArray("2", aSelected) != -1)

If you do this: ($.inArray("2", aSelected) == 0)
Then you are checking if "2" is the first selected option, but if the user also selects "1", then $.inArray("2", aSelected) will return 1, not 0.
#812782
Hello in the new year!
I was away from working on processmaker for almost a month...

I've changed the statement from: !=0 to == -1 for the missing values and everything works fine
example below:

if ($.inArray("1", aSelected) != -1 && $.inArray("2", aSelected) != -1 && $.inArray("3", aSelected) == -1 )

But You were right about the issues with the code :) Thank You for bringing this to my attention :)

By the way i have two questions:

1. Question about form.getField() function and it's description on wiki. I can't force it to work on 3.2.1 community, console says: Uncaught TypeError: $(...).getFields is not a function. Is it only enterprise edition function?

code from wiki
Code: Select all
$('#btnFormFields').on('click', function(e) {
    var fields;
    e.preventDefault();
    fields = $('#590857782596fc2fd9cad32087250836').getFields();
    for (var i=0;i< fields.length;i++){
        fields[i].disableValidation();
    }
});
2. Is it possible to change the whole Form display mode from Edit to View or Disabled using a button or something like that?

Regards,
#812783
I just checked getFields() and it always returns an empty array, so it has a bug in it.

To work around the problem, you can use this code to get an array of the fields in a form:
getFormById( $("form").prop("id") ).model.attributes.project.fields

For example, you can use this code:
Code: Select all
$('#btnFormFields').on('click', function(e) {
    var fields;
    e.preventDefault(); //only necessary for submit buttons
    fields = getFormById( $("form").prop("id") ).model.attributes.project.fields;
    for (var i=0; i < fields.length; i++){
        fields[i].disableValidation();
    }
});
#812784
To make all the input fields read-only, you can do something like this:
Code: Select all
var aFieldTypes = ["text", "textarea", "dropdown", "radio", "checkbox", "checkgroup", "suggest", "datetime"];
$('#btnReadOnly').find("button").click( function() {
    var aFields = getFormById( $("form").prop("id") ).model.attributes.project.fields;
    for (var i=0; i < fields.length; i++) {
        var fieldType = fields[1].getInfo().type;
        if ($.inArray(fieldType, aFieldTypes) != -1) {
            fields[i].getControl().prop("disabled", true);
        }
    }
});
I haven't tested it on all types of fields, so it might require some debug.
#812792
After a few tests I've found what is wrong, example below:

Example1

one row
col-span:4 4 4
textbox1 | empty | textbox2

button

When I push the Button, then the error shows: VM14551:5 Uncaught TypeError: aFields.getInfo is not a function
textbox1: is disabled
textbox2: is enabed

Example2

one row
col-span:4 4 4
textbox1 | textbox2 | textbox3

button

When I push the Button, then there is no errors and:
textbox1: is disabled
textbox2: is disabled
textbox3: is disabled


Conclusion
If a row is divided by col-span, then all fields need to be filled with any type of the Web Control because if we leave an empty field, then the error will occur.


Code: Select all
var aFieldTypes = ["text", "textarea", "dropdown", "radio", "checkbox", "checkgroup", "suggest", "datetime"];
$('#btnReadOnly').find("button").click( function() {
    var aFields = getFormById( $("form").prop("id") ).model.attributes.project.fields;
    for (var i=0; i < aFields.length; i++) {
        var fieldType = aFields[i].getInfo().type;
        if ($.inArray(fieldType, aFieldTypes) != -1) {
            aFields[i].getControl().prop("disabled", true);
        }
    }
});
#812808
Oh, I see the problem. Not all fields/controls in a Dynaform have getInfo().
Try this:
Code: Select all
var aFieldTypes = ["text", "textarea", "dropdown", "radio", "checkbox", "checkgroup", "suggest", "datetime"];
$('#btnReadOnly').find("button").click( function() {
    var aFields = getFormById( $("form").prop("id") ).model.attributes.project.fields;
    for (var i=0; i < aFields.length; i++) {
        //check if properties exist:
        if (aFields[i].getInfo && aFields[i].getInfo().type) {
           var fieldType = aFields[i].getInfo().type;
           if ($.inArray(fieldType, aFieldTypes) != -1) {
             aFields[i].getControl().prop("disabled", true);
           }
        }
    }
});
#812815
Hi,
Yup, everything works just fine :)

I have a last question ( I HOPE ;P ) about the grids...

Example below:
I have 3 grids in 3 forms:
- Form1, grid1
- Form2, grid2
- Form3, grid3
All three grids have the same fields: userID, Product, Price.

Before Form3 is loaded, the data from the two grids is merged into grid3. When the Form3 is loaded the data from grid1 and grid2 is in grid3.

Now, on Form3, when I click the button (count) I would like to sum the price per each user to the two new fields: user1_sum, user2_sum.

Question:
How to sum the Price per userID in grid.

I was trying to do something like code below but of course it does not work if there is more than one user. (this code is not copied directly from my form because my form is a bit more complicated)
Code: Select all
function roundToFixed(_float, _digits) {
   var rounder = Math.pow(10, _digits);
   return (Math.round(_float * rounder) / rounder).toFixed(_digits);
}

$("#ButtonCount").setOnchange( function(newVal, oldVal) {
  if (newVal == '"1"' || newVal == '["1"]') {
    var userID = ["user1", "user2", "user3"] ;    //issue1: this does not work
    var numRows = $("#Grid3").getNumberRows();
    for (var i=1; i <= numRows; i++) {
      //issue1: this does not work. Works if userID is set manually -> == "user1"
      if ($("#Grid3").getText(i, 1) == userID) { 
        var totalCost = parseFloat($("#Grid3").getSummary("Price"));     //
        for (var i = 1; i <= numRows; i++) {
          price_user = parseFloat($("#Grid3").getValue(i, 3));
          $("#user1_sum").setValue(roundToFixed(totalCost, 2)); 
        }
      }    
    }
  }
}; 
 
#812820
I see a couple problems with your code. Buttons don't have values and the setOnchange() method doesn't work with them. You need to use click() instead. Also you forgot to terminate your event handler code with ).
If you have a fixed number of users and userX_sum fields, then you can do something like this:
Code: Select all
$("#ButtonCount").find('button').click( function() {
  var checkVal = $("#mycheckbox").getValue();
  if (checkVal == '"1"' || checkVal == '["1"]') {
    var aUserIDs = ["user1", "user2", "user3"];
    var aSumFields = ["user1_sum", "user2_sum", "user3_sum"];
    var numRows = $("#Grid3").getNumberRows();

    //loop for each row in Grid3:
    for (var i=1; i <= numRows; i++) {
      //loop for each user:
      for (var ii = 0; ii < aUserIDs.length; ii++) {
        var userSum = 0;
        //add price if matching user:
        if ($("#Grid3").getText(i, 1) == $aUserIDs[ii]) {
          userSum += parseFloat( $("#Grid3").getValue(i, 3) );
        }
        
        $("#" + aSumFields[ii]).setValue( roundToFixed(userSum, 2) ); 
      }    
    }
  }
});
#812836
Hi,
Something is wrong.

Code below and sample process attached that simulates 3rd form with Grid3.
When I add:
- row: 1,2 with user1 and click count button: only price from last row is visible (no sum)
- row 1: user1, row 2: user2: only price from last row is visible ( user1 gets 0, user2: price )
- row 1: user1, row 2: user2, row 3: user2: only price from last row is visible (user1 gets 0, user2: price from row3 (no sum from row2 and row3) )


Code: Select all
function roundToFixed(_float, _digits) {
   var rounder = Math.pow(10, _digits);
   return (Math.round(_float * rounder) / rounder).toFixed(_digits);
}



$("#ButtonCount").find('button').click( function() {
 // var checkVal = $("#mycheckbox").getValue();
  //if (checkVal == '"1"' || checkVal == '["1"]') {
    var aUserIDs = ["user1", "user2", "user3"];
    var aSumFields = ["user1_sum", "user2_sum", "user3_sum"];
    var numRows = $("#Grid3").getNumberRows();

    //loop for each row in Grid3:
    for (var i=1; i <= numRows; i++) {
      //loop for each user:
     
      for (var ii = 0; ii < aUserIDs.length; ii++) {
      var userSum = 0;   
        //add price if matching user:
        if ($("#Grid3").getText(i, 1) == aUserIDs[ii]) {
          userSum += parseFloat( $("#Grid3").getValue(i, 3) );
        }
        
        $("#" + aSumFields[ii]).setValue( roundToFixed(userSum, 2) ); 
      }    
    }
  }
);


Attachments
(28.5 KiB) Downloaded 292 times
#812867
The user needs to be the outer for loop, like this:
Code: Select all
function roundToFixed(_float, _digits) {
   var rounder = Math.pow(10, _digits);
   return (Math.round(_float * rounder) / rounder).toFixed(_digits);
}

$("#ButtonCount").find('button').click( function() {
 // var checkVal = $("#mycheckbox").getValue();
  //if (checkVal == '"1"' || checkVal == '["1"]') {
    var aUserIDs = ["user1", "user2", "user3"];
    var aSumFields = ["user1_sum", "user2_sum", "user3_sum"];
    var numRows = $("#Grid3").getNumberRows();
    
    //loop for each user:
    for (var ii = 0; ii < aUserIDs.length; ii++) {
      var userSum = 0;   
      //loop for each row in Grid3:
      for (var i=1; i <= numRows; i++) {
        //add price if matching user:
        if ($("#Grid3").getText(i, 1) == aUserIDs[ii]) {
          userSum += parseFloat( $("#Grid3").getValue(i, 3) );
        }
      }
      $("#" + aSumFields[ii]).setValue( roundToFixed(userSum, 2) );   
    }
}
); 
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]