These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Make Field Required if Checkbox is selected Validate Error LiveCycle

ttodd
Registered: Nov 21 2009
Posts: 3

I am trying to write a simple script that will allow certain text fields to be required based on a checkbox, drop down list, or radio button. For example if the user chooses buyer, text fields about buyer information will be displayed and required, if the user chooses seller, text fields about seller information will be displayed and required, if the user chooses buyer and seller text fields for both buyer and seller will be displayed.

I am using LiveCycle 8.2.

While experimenting, I used the following script

if (this.rawValue == 1){Buyer.mandatory = "error";}
else {Buyer.mandatory = "disabled";}

I placed this script under

Buyer.#subform[0].buyercheck::validate - (JavaScript, client) for the object buyercheck (checkbox),
Java script and run at client selected are selected.

If I use the check box, the drop down list, or the radio buttons I get the following error when opening the form or when I check the button

"buyercheck validate failed."

Buyercheck is my check box used to make buyer text mandatory. Interestingly the text box will show red, but I get the error and can not submit the form.

What am i doing wrong. I'm very new to this and can't figure this out. Any help will be greatly appreciated!

Terri

My Product Information:
LiveCycle Designer, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
In a validate event the last thing evaluated is the return value. If it evaluates to true, then the fields passed validation, if it evaluates to false, then the field failed validation. Apparently your "if" statment is evaluating to false. You could fix this one issue by placing "true;" at the end of the script. Another solution would be to use the same code in the MouseUp event.

Have you watched this video, it covers some of the issues you mentioned:
https://admin.adobe.acrobat.com/_a200985228/p87746471/

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

ttodd
Registered: Nov 21 2009
Posts: 3
Thank you very much for the information! The video you suggested was great! It helped immensely! I created sub-forms. My code works now, but I wonderful if there was a way to call all fields in a sub form without typing each one. For Example my code is as follows:

if (this.rawValue == 1){TypeSeller.SellEmail.mandatory = "error"; TypeSeller.SellName.mandatory = "error";TypeBuyer.BuyerEmail.mandatory = "disabled"; TypeBuyer.BuyerName.mandatory = "disabled";}
if (this.rawValue == 2){TypeBuyer.BuyerEmail.mandatory = "error"; TypeBuyer.BuyerName.mandatory = "error"; TypeSeller.SellEmail.mandatory = "disabled"; TypeSeller.SellName.mandatory = "disabled"}
if (this.rawValue == 3){TypeSeller.SellEmail.mandatory = "error"; TypeSeller.SellName.mandatory = "error"; TypeBuyer.BuyerEmail.mandatory = "error"; TypeBuyer.BuyerName.mandatory = "error";} true;

The example only has two fields for seller and two fields for buyer, but the real form will have about 15-20 fields for buyer and 15-20 fields for seller. Is it possible to make all fields mandatory by calling the sub-form?


Thank you,

Terri
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
When changing any individual field property there has to be a line of code for each field, they cannot be changed en-mass. However, there are different ways to write this code. For example you can use a conditional statement.
var bSeller = (this.rawValue != 2);var bBuyer = (this.rawValue != 1);TypeSeller.SellEmail.mandatory = bSeller?"disabled":"error";TypeSeller.SellName.mandatory = bSeller?"disabled":"error";

This makes the code a bit shorter.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script