Expand my Community achievements bar.

SOLVED

Script questions on required fields

Avatar

Level 2

I am an absolute newbie to scripting, so I do a lot of copying and pasting and editing from online. Here is my problem: I am creating a license application form in LiveCycle Designer ES 8.2 (the free one with Acrobat Professional 9). I have about a dozen or so fields (basic demographic info) that I made required on the form (this I did through the Object>Value>User Entered-Required palette). I have a checkbox that the licensees would check if they are operating at more than one facility. I "figured out" how to do this (read: Google searched and copy and pasted), and I know it's working because when they check the box the border around the text field turns red indicating a required field. If the required fields are not filled in, I want a message to pop up when they try to Print telling them that they need to fill out the required fields. I "figured out" how to do this, but the script required me to individually list each field that is required. How do I achieve this error message, taking into account the text field that may or may not be required based on if they checked the checkbox or not?

Thanks in advance,

Scott

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

You can execute all of the validations on a form with a single command and it wil return a true if one of the validations fails or a false if there are no validation errors. So on the button that the user clicks (it needs to be a regular button) you could write code like this on the click event:

if (form1.execValidate() == false){

     app.alert("You have not filled out all of the required fields....")

} else {

     put your print command here......

}

This assumes that your root node in the form is form1 (look at the top level node in the hierarchy view).

Hope that helps

Paul

View solution in original post

5 Replies

Avatar

Level 10

You might follow the steps below and if you have issues , please let me know..

prePrint event with JavaScript:

var mandatoryMissed = "";

if(checkbox.rawValue = "1"){

     if(TextField1.rawValue == null || TextField1.rawValue == ""){

          mandatoryMissed = mandatoryMissed + ", " + "TextField1";

     }

     .......Do the same for each of the mandatory field on your form.

}

if(mandatoryMissed != ""){

     xfa.host.messageBox("The below mandatory fields are missing input." + mandatoryMissed);

}

Finally the mandatoryMissed variable can have all the names of the mandatory missed fields..

Use messageBox method to display the mandatoryMissed string to the user in the prePrint event..

Thanks

Srini

Avatar

Correct answer by
Former Community Member

You can execute all of the validations on a form with a single command and it wil return a true if one of the validations fails or a false if there are no validation errors. So on the button that the user clicks (it needs to be a regular button) you could write code like this on the click event:

if (form1.execValidate() == false){

     app.alert("You have not filled out all of the required fields....")

} else {

     put your print command here......

}

This assumes that your root node in the form is form1 (look at the top level node in the hierarchy view).

Hope that helps

Paul

Avatar

Level 2

Thanks to you both for your help. Srini,my limited knowledge makes it hard for me to exactly follow your script - would I put this on the Print button or another button? Does it include the command to print if all required fields are filled in?

Paul, I think yours was a little easier to follow. It seemed to work, but something weird is happening (probably from the original script for making the text field mandatory from the checkbox). Let me outline my sample form and provide the script and tell you the weird thing:

Checkbox (named Multiple)

TextField (named ListNames)

TextField (named Other - made this one a required field)

Button (named Fake - on top of the Print button)

Print Button (named Print)

The script on Multiple is:

if

(this.rawValue == 1){ListNames.mandatory = "error";}

else

{ListNames.mandatory = "disabled";}

true;

The script on Fake is:

if

(form1.execValidate() == false){

app.alert("You have not filled out all of the required fields....") } else {

xfa.host.print(1, "0", (xfa.host.numPages -1).toString(), 0, 0, 0, 0, 0);

ListNames.validate.nullTest = "error";

}

When I test it out without the Multiple checked and data in Other, it goes to the print dialogue box (yea!) but then a red border appears around the ListNames box. Otherwise, all testing is good.  

Avatar

Former Community Member

Can you post the form so I can have a look ....it is hard to do this without context. You can email the form to LiveCycle8@gmail.com

Paul

Avatar

Former Community Member

Hi Paul,

I wonder if you could help with a similar problem I am having with required fields? I want to add a button to my form which users can click on to check that all fields that have been set as required have been filled in. If the required fields are not filled in I want a message to come up and say thet the required fields need to be completed. I know you can add a submit by email button which works similar but as my workflow is slightly different I do not want it to automaticaly generate an email for submission. I'm not really familiar with code so am striggling slightly!

Any help much appreciated.

Ken

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----