Skip to main content
shannonk95
Participating Frequently
July 26, 2018
Question

Show a field if all checkboxes are checked

  • July 26, 2018
  • 2 replies
  • 1134 views

I have a PDF checklist with 12 checkboxes named Pass1.0, Pass1.1 and so on up to Pass1.11.

There's a Visible text field called CompletePrompt at the top of the page on top of a Hidden signature field.

There is a Sign Checklist button at the bottom of the page. When clicked, the following js runs:

this.getField("CompletePrompt").display = display.hidden;

this.getField("ReviewerSignature").display = display.visible;

this.getField("ReviewerSignature").setFocus();

this.getField("ReviewerSignature").strokeColor = color.red;

I want this to happen if and only if every one of the 12 checkboxes is checked. If even one box is blank, I want the script to end and trigger an app.alert without toggling the visibility of the other fields.

My current effort ended in:

var f = this.getField("Pass1");

if (f.valueAsString == "Off") {

     app.alert({cMsg:"Check all Checkboxes to Sign"});

} else if (f.valueAsString == "Yes") {

     this.getField("CompletePrompt").display = display.hidden;

     this.getField("ReviewerSignature").display = display.visible;

     this.getField("ReviewerSignature").setFocus();

     this.getField("ReviewerSignature").strokeColor = color.red;

}

What am I doing wrong here?

This topic has been closed for replies.

2 replies

shannonk95
Participating Frequently
July 26, 2018

This is the final code snippet that works to hide a Signature field under a different text field until all checkboxes in a list are checked off.

var allChecked = true;

  

for (var i=1; i<=12; i++) {

  var f = this.getField("Pass"+i);

    if (f.valueAsString=="Off"){

      allChecked = false;

      break;

}

}

if (allChecked == false) {

    app.alert({cMsg:"Complete checklist first!"});

} else if (allChecked == true){

    this.getField("CompletePrompt").display = display.hidden;

    this.getField("ReviewerSignature").display = display.visible;

    this.getField("ReviewerSignature").setFocus();

    this.getField("ReviewerSignature").strokeColor = color.red;

}

try67
Community Expert
Community Expert
July 26, 2018

The value property is unique to each field. You can't access all of the fields' values by access the parent one.

You'll need to use a loop to iterate over all the fields, checking all of their values.

shannonk95
Participating Frequently
July 26, 2018

Edit: I tried the below code. The error message works perfectly. However, when I check all the checkboxes and then click the Sign Checklist button, an error message is displayed in the JS debugger "Type f is null".

I'm not the greatest at js loops, i know I have to use something like the following:

for (var i=0; i<=12; i++) {

     var f = this.getField("Pass1."+i);

          if (f.valueAsString=="Off"){

               app.alert({cMsg:"Check all Checkboxes to Sign"});

               break;

          } else if (f.valueAsString=="Yes"){

               this.getField("CompletePrompt").display = display.hidden;

               this.getField("ReviewerSignature").display = display.visible;

               this.getField("ReviewerSignature").setFocus();

               this.getField("ReviewerSignature").strokeColor = color.red;

          }

     }

Could you please let me know if I have the syntax wrong? I'm basing it off one of your answers on these forums.

try67
Community Expert
Community Expert
July 26, 2018

The syntax is fine, but the logic you used is incorrect. You should use a Boolean variable to keep track of the values of the fields inside the loop (if the value is "Off" set it to false, otherwise leave it as true), and after it check that variable to make sure that none of the fields were off (ie, if the variable is true, it's all good). Then show the error message/enable the fields based on it.