Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

checkbox action to trigger text field

Explorer ,
May 11, 2020 May 11, 2020

I have a working mouse up JS which hides and/or requires text fields based on the selection of the checkbox.  Could I get some help with converting it to a document level JS as it will be used with multiple groups of checkboxes and text fields?

var f = this.getField("UCCJEA - pg 1 - persons with physical custody of child(ren)");
var g = this.getField("UCCJEA - pg. 1 - info of person with custody of child(ren)");
var h = this.getField("UCCJEA - pg. 1 - info of persons with custody of child(ren)");
var i = this.getField("UCCJEA - pg. 1 - info of other person with custody of child(ren)");
var j = this.getField("UCCJEA - pg. 1 - info of other persons with custody of child(ren)");

if (f.value == "no parties exist")
{
g.hidden = true;
g.required = false;
g.value = "";
h.hidden = true;
i.hidden = true;
j.hidden = true;
}
else
if (f.value == "parties who have physical custody but are not part of proceeding")
{
g.hidden = false;
g.required = true;
g.setFocus();
h.hidden = false;
i.hidden = false;
j.hidden = false;
}
else
{
g.hidden = true;
g.required = false;
g.value = "";
h.hidden = true;
h.value = "";
i.hidden = true;
i.value = "";
j.hidden = true;
j.value = "";
}

 Thanks

Meabh

TOPICS
Create PDFs , PDF forms
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2020 May 11, 2020

Do you mean you want to create a generalized document level function that will work with any group of checkboxes?  

If so then key to this process is in the commonality of the elements involved,i.e., the field names and the values used in the "if" statements.  

 

So the names of the other feilds will need to be derived from the name of the field triggering the script. 

I'd suggest you start by coming up with a checkbox and text field naming convetion that will be the same for each group. 

The "if" comparison values can be derived from "exports" property of the triggering field.  

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 11, 2020 May 11, 2020

I was afraid you'd say something like that.  I have a script that pulls the name of any fields that are required but not completed such as "Petition - pg 2 - date of court order" before allowing email submittal.  I wanted to give the user some idea of the missing required field in an 8 page package of 4 different forms.  The above script was for 4 text fields, the next group has 16. I can keep going with it but I'm concerned over the number of field level JS and potential conflicts and thought a document level would be less clunky.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2020 May 11, 2020

A doc level function would be less clunky as well as more robust and easier to maintain, since changes would only need to be made in one place. 

 

You have to think about these things when creating a form design. The field, names, types, scripts, and how the data will be used, all go together.  For example, if groups of fields will be handled in the same way, but have different numbers of members, then they should be prefixed with a group name. The scripts handling these field groups can then be written to handle any number of members, because the members can be identified. 

 

Good form design in an art. It takes attention to detail and effort to be effective. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2020 May 12, 2020

I try to be mindful of a naming convention (not the 1st time you've advised me of this!) and I THINK what I have will work.  Each of the required fields name follow this convention: 'form name - pg # - specific field' so the doc level can reference the 'form name - pg #' portion, correct? Potentialy I will still have at least 2 doc level functions (based on the groups in the form) but thats will preferable to what I've currently got

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2020 May 11, 2020

Side-note: The hidden property is deprecated. Use the display property, instead.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 12, 2020 May 12, 2020
LATEST

My current version adapted from other scripts

getField("UCCJEA - pg. 1 - info of person with custody of child(ren)").display = event.target.value == "Off" ? display.hidden : display.visible;

this.getField("UCCJEA - pg. 1 - info of person with custody of child(ren)").required = true;
this.getField("UCCJEA - pg. 1 - info of person with custody of child(ren)").setFocus();
this.getField("UCCJEA - pg. 1 - info of person with custody of child(ren)").value = "";

getField("UCCJEA - pg. 1 - info of persons with custody of child(ren)").display = event.target.value == "Off" ? display.hidden : display.visible;
getField("UCCJEA - pg. 1 - info of persons with custody of child(ren)").value = "";

getField("UCCJEA - pg. 1 - info of other person with custody of child(ren)").display = event.target.value == "Off" ? display.hidden : display.visible;
getField("UCCJEA - pg. 1 - info of other person with custody of child(ren)").value = "";

getField("UCCJEA - pg. 1 - info of other persons with custody of child(ren)").display = event.target.value == "Off" ? display.hidden : display.visible;
getField("UCCJEA - pg. 1 - info of other persons with custody of child(ren)").value = "";

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines