Skip to main content
Inspiring
March 25, 2024
Question

Trying to made a signature field read only unless all checkboxes in a PDF form are checked

  • March 25, 2024
  • 1 reply
  • 830 views

Good morning,

I have a PDF form which I've been tasked to make it so that the signature field only activates if all checkboxes in the form have been checked.

I had Chat GPT write a script which seems to work to make the signature field read only until all boxes are checked, but then when I try to apply the signature it gives me an error which states "The document cannot be signed in its current state.  Please save the document, close it, reopen it, and then attempt to sign again".

I tried that multiple times but I keep getting the same error message.

Any help would be greatly appreciated.

This topic has been closed for replies.

1 reply

Inspiring
March 25, 2024

Well, I think I figured it out.  Rather than putting in a document-level script or a custom calculation script in a hidden text field, I just had to add this as a Mouse-Up action to each of the 62 check boxes:

 

var checkbox1 = this.getField("CheckBox01").value;
var checkbox2 = this.getField("CheckBox02").value;
var checkbox3 = this.getField("CheckBox03").value;
var checkbox4 = this.getField("CheckBox04").value;
var checkbox5 = this.getField("CheckBox05").value;
var checkbox6 = this.getField("CheckBox06").value;
var checkbox7 = this.getField("CheckBox07").value;
var checkbox8 = this.getField("CheckBox08").value;
var checkbox9 = this.getField("CheckBox09").value;
var checkbox10 = this.getField("CheckBox10").value;
var checkbox11 = this.getField("CheckBox11").value;
var checkbox12 = this.getField("CheckBox12").value;
var checkbox13 = this.getField("CheckBox13").value;
var checkbox14 = this.getField("CheckBox14").value;
var checkbox15 = this.getField("CheckBox15").value;
var checkbox16 = this.getField("CheckBox16").value;
var checkbox17 = this.getField("CheckBox17").value;
var checkbox18 = this.getField("CheckBox18").value;
var checkbox19 = this.getField("CheckBox19").value;
var checkbox20 = this.getField("CheckBox20").value;
var checkbox21 = this.getField("CheckBox21").value;
var checkbox22 = this.getField("CheckBox22").value;
var checkbox23 = this.getField("CheckBox23").value;
var checkbox24 = this.getField("CheckBox24").value;
var checkbox25 = this.getField("CheckBox25").value;
var checkbox26 = this.getField("CheckBox26").value;
var checkbox27 = this.getField("CheckBox27").value;
var checkbox28 = this.getField("CheckBox28").value;
var checkbox29 = this.getField("CheckBox29").value;
var checkbox30 = this.getField("CheckBox30").value;
var checkbox31 = this.getField("CheckBox31").value;
var checkbox32 = this.getField("CheckBox32").value;
var checkbox33 = this.getField("CheckBox33").value;
var checkbox34 = this.getField("CheckBox34").value;
var checkbox35 = this.getField("CheckBox35").value;
var checkbox36 = this.getField("CheckBox36").value;
var checkbox37 = this.getField("CheckBox37").value;
var checkbox38 = this.getField("CheckBox38").value;
var checkbox39 = this.getField("CheckBox39").value;
var checkbox40 = this.getField("CheckBox40").value;
var checkbox41 = this.getField("CheckBox41").value;
var checkbox42 = this.getField("CheckBox42").value;
var checkbox43 = this.getField("CheckBox43").value;
var checkbox44 = this.getField("CheckBox44").value;
var checkbox45 = this.getField("CheckBox45").value;
var checkbox46 = this.getField("CheckBox46").value;
var checkbox47 = this.getField("CheckBox47").value;
var checkbox48 = this.getField("CheckBox48").value;
var checkbox49 = this.getField("CheckBox49").value;
var checkbox50 = this.getField("CheckBox50").value;
var checkbox51 = this.getField("CheckBox51").value;
var checkbox52 = this.getField("CheckBox52").value;
var checkbox53 = this.getField("CheckBox53").value;
var checkbox54 = this.getField("CheckBox54").value;
var checkbox55 = this.getField("CheckBox55").value;
var checkbox56 = this.getField("CheckBox56").value;
var checkbox57 = this.getField("CheckBox57").value;
var checkbox58 = this.getField("CheckBox58").value;
var checkbox59 = this.getField("CheckBox59").value;
var checkbox60 = this.getField("CheckBox60").value;
var checkbox61 = this.getField("CheckBox61").value;
var checkbox62 = this.getField("CheckBox62").value;

var signatureField = this.getField("SignatureField");

if (checkbox1 == "Off" || checkbox2 == "Off" || checkbox3 == "Off" || checkbox4 == "Off" || checkbox5 == "Off" || checkbox6 == "Off" || checkbox7 == "Off" || checkbox8 == "Off" || checkbox9 == "Off" || checkbox10 == "Off" || checkbox11 == "Off" || checkbox12 == "Off" || checkbox13 == "Off" || checkbox14 == "Off" || checkbox15 == "Off" || checkbox16 == "Off" || checkbox17 == "Off" || checkbox18 == "Off" || checkbox19 == "Off" || checkbox20 == "Off" || checkbox21 == "Off" || checkbox22 == "Off" || checkbox23 == "Off" || checkbox24 == "Off" || checkbox25 == "Off" || checkbox26 == "Off" || checkbox27 == "Off" || checkbox28 == "Off" || checkbox29 == "Off" || checkbox30 == "Off" || checkbox31 == "Off" || checkbox32 == "Off" || checkbox33 == "Off" || checkbox34 == "Off" || checkbox35 == "Off" || checkbox36 == "Off" || checkbox37 == "Off" || checkbox38 == "Off" || checkbox39 == "Off" || checkbox40 == "Off" || checkbox41 == "Off" || checkbox42 == "Off" || checkbox43 == "Off" || checkbox44 == "Off" || checkbox45 == "Off" || checkbox46 == "Off" || checkbox47 == "Off" || checkbox48 == "Off" || checkbox49 == "Off" || checkbox50 == "Off" || checkbox51 == "Off" || checkbox52 == "Off" || checkbox53 == "Off" || checkbox54 == "Off" || checkbox55 == "Off" || checkbox56 == "Off" || checkbox57 == "Off" || checkbox58 == "Off" || checkbox59 == "Off" || checkbox60 == "Off" || checkbox61 == "Off" || checkbox62 == "Off") {
signatureField.display = display.hidden;
} else {
signatureField.display = display.visible;
}

Thom Parker
Community Expert
Community Expert
March 25, 2024

First, ChatGPT is crap and will not write correct code for Acrobat scripts. 

 

Now, your script is very straight forward, but could be massively simplify in a coulple of different ways. 

1. Since the checkbox field names follow a pattern using progressive numbers, a loop can be used to collect and test the values.

 

2. The form can be made much better by using descriptive and grouped name patterns. Grouping fields allows them to be handled together. So if all the checkboxes were named like this.  "CheckGrp.Check1","CheckGrp.Check2","CheckGrp.Check3", etc. 

 

Then this script solves your issue:

 

this.getField("Signature1").display = (this.getField("CheckGrp").getArray().every(a=>a.value != "Off"))?display.visible:display.hidden;

 

On another note. It is an exceedingly bad strategy to place the entire script into the mouse up of every single checkbox.  

At the very least this code should be defined as a document level function. But it really is much better for this type of thing to use a calculation script in a hidden field. 

 

 

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Inspiring
March 25, 2024

Haha, well, Chat GTP may be crap at writing scripts, but it's better than me!  I don't know how to write codes, it's still like trying to cast spells for me, I try and google the right ingredients and hope it works.

When I tried using loops and both when I tried doing the hidden calculation field or the document-level script I'd get that "The document cannot be signed in its current state.  Please save the document, close it, reopen it, and then attempt to sign again" error.

When I get a minute, I'll try your code and let you know what happens.  Thanks for your response!