3 Replies Latest reply on Feb 4, 2014 6:10 AM by Magus069

    How can I do my own validation of a form

    Paul Dokken Level 1

      I have a LiveCycle form with 3 tables that the number of rows can vary.  I would like to validate the table by saying any row with at least one column value in it must have all columns filled.  Any row with all blank columns can be considered valid.How would I do this?

       

      Thanks,

      Paul

        • 1. Re: How can I do my own validation of a form
          Magus069 Level 4

          //Using a click_event on a button

           

          //create a bool variable

          var boValidate = true;

           

          //create a string variable for somExpressions

          var strExpression = "";

           

          for (var i = 0; i < xfa.resolveNode("Page1.Table1.Row1").instanceManager.count; i++){

               if (xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell1").rawValue != null || xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell2").rawValue != null ||

                    xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell3").rawValue != null || xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell4").rawValue != null){

                    if (xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell1").rawValue == null){

                         boValidate = false;

                         strExpression = xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell1").somExpression;

                    }else if(xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell2").rawValue == null){

                         if (boValidate){

                              boValidate = false;

                              strExpression = xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell2").somExpression;

                         }

                    }else if(xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell3").rawValue == null){

                         if (boValidate){

                              boValidate = false;

                              strExpression = xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell3").somExpression;

                         }

                    }else if(xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell4").rawValue == null){

                         if (boValidate){

                              boValidate = false;

                              strExpression = xfa.resolveNode("Page1.Table1.Row1[" + i.toString() + "].Cell4").somExpression;

                         }

                    }

               }

          }

           

          //the code above is only for one table... you can add as many validation as you want with this

          //by verifying if boValidate is always true, you can only take the somExpression of the first field that failed validation

           

          if (!boValidate){

               //at the end of the validation here you focus on the first object that validation has failed

               xfa.host.setFocus(strExpression);

          } else{

               //send email

               //print form

          }

          • 2. Re: How can I do my own validation of a form
            Paul Dokken Level 1

            This example is helpful.  I am just missing how to do the validation.  Would I run this code from my submit button on the form and cancel the submit if the anything is invalid?  How would I do this?

             

            Thanks,

            Paul

            • 3. Re: How can I do my own validation of a form
              Magus069 Level 4

              I would just put the code inside a normal button, if you need to submit, print, save, or send by email you can always do it in a normal button