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

Conditional mandatory field

mkhennafi
Registered: Jul 2 2009
Posts: 15

Good evening gurus:

I have two fields that are interdependent.
- Field1 is set up as a drop down with 4 values (V1, V2, V4, V4)
- Field2 is a text box.

What i would like to achieve is the following:
- If field1 selected value is V1, then filling in field 2 is mandatory and the user cannot leave the field blank (checking that the field is not filled in with spaces is also necessary)
- if field1 value is not V1 then filling in field2 is not mandatory

Any suggestion on how to setup the javascript code? Is it a field level or document level script?

Any direction on a source of information for required field values other than setting it up in the properties window?

Thanks for helping!

MK

My Product Information:
Acrobat Pro Extended 9.1.3, Windows
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
Set Field1 option for "Commit selected value immediately". Then in Field1 on Mouse Up:
getField("Field2").required = (event.target.value == "V1");
Then, use our tools to create Field2 with a custom validation with a Regular Expression of:
^\S+

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

mkhennafi
Registered: Jul 2 2009
Posts: 15
Thanks very much for your time and energy!

I followed lead and did exactly what you recommend, I was able to submit the form even if my field value was left blank...
jimhealy
Team
Registered: Jan 2 2006
Posts: 146
Can you send me your form?

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com

jimhealy
Team
Registered: Jan 2 2006
Posts: 146
Your "ToCode" field has some bugs in the validation. Change it to:
/* force the value if RGC */var RT=this.getField("ReturnType");var TC=this.getField("ToCode");if (RT.value=="Return Goods Center"){TC.value="41";}

In your "ReturnType" field, add this Javascript as an On Blur action (Mouse Up was a mistake by me):
getField("RGA Number").required = (event.target.value == "RGC");
Finally, use our tools to re-create "RGA Number" with a custom validation with a Regular Expression of:
^\S+

Jim Healy
FormRouter, Inc.
Check out our FREE Advanced Acroform Toolset:
http://www.formrouter.com/tools

Jim Healy, Founder & CEO FormRouter Inc.
Chapter Leader AUG RTP NC
http://www.formrouter.com