1
0
-1

Hi,

I am trying to implement a feature where the user will select the Total Container, lets say '3'. Automatically this act as a validator and restrict the number of rows that can be added in a grid. Example similar to Figure 1.


Is there a way or method of achieving this?


                                                                   Figure 1 


    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      I think you need to use a bean shell multirow validator on the grid.

      and code something like this?

      import java.util.Arrays;
      import org.joget.apps.app.service.AppUtil;
      import org.joget.apps.form.model.Element;
      import org.joget.apps.form.model.Form;
      import org.joget.apps.form.model.FormData;
      import org.joget.apps.form.service.FormUtil;
      import org.joget.apps.form.model.FormRow;
      import org.joget.apps.form.model.FormRowSet;
       
      public boolean validate(Element element, FormData formData, FormRowSet fgRows) {
          boolean result = true;
          
          System.out.println(" fgRows size  >>>>>>>>> "+fgRows.size()+"\n");
          int gridSize = fgRows.size();
       
          //get selectbox value from form data object
          String field1Id = "totalContainer";// your selectbox field id
          Form form = FormUtil.findRootForm(element);
          Element field1 = FormUtil.findElement(field1Id, form, formData);
       
          if (field1 != null) {
              //get value of field 1
              String compareValues = FormUtil.getElementPropertyValue(field1, formData);
              System.out.println(" compareValues  >>>>>>>>> "+compareValues+"\n");
              int i=Integer.parseInt(compareValues);  
       
              //compare the value of gridsize and field 1 are equals
              if (gridSize!=i) {
                  String id = FormUtil.getElementParameterName(element);
                  formData.addFormError(id, "Value not equal!!!!");
                  result = false;
              }
          } else {
              //ignore if the field 1 not exist
          }
       
          return result;
      }
       
      //call validate method with injected variable
      return validate(element, formData, rows);

      I used this as a reference:

      Bean Shell Programming Guide - Knowledge Base for DX 7 - Joget | COMMUNITY

      1. Danial Jefri

        Hi, I will look into this method. Thank you.

      CommentAdd your comment...