Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

How can I do my own validation of a form

Avatar

Level 2

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

3 Replies

Avatar

Level 10

//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

}

Avatar

Level 2

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

Avatar

Level 10

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