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

javascript make fields read-only until signature field is filled

Community Beginner ,
Apr 17, 2025 Apr 17, 2025

I have a script that works for most but not all of my use cases. It runs on "mouse up" on the second signature field in my form, which is set to read-only by default. The intent is to keep the second signature field as read-only unless the first signature field is filled in. Here's the full script:

 

if(this.getField("Signature1").signatureValidate()==0)

{this.getField("Signature2").readonly = true; app.alert("Signature1 needs to be completed before you can sign here.")}

else

{this.getField("Signature2").readonly = false; }

 

The issue I'm having is that if a user's signature won't validate, but is present, it won't allow the second signature field to be signed. I realize that this might present security issues, but I am unconcerned with a signature actually validating, I just need it to be there.

 

I think my question is simple! What do I substitute for this part of my script,

 

.signatureValidate()==0

 

to just require that the first signature be not blank,  rather than validated? I tried a couple things like:

 

.value!=null

 

.value!=""

 

But they didn't work for me.

TOPICS
How to , JavaScript , PDF , PDF forms , Security digital signatures and esignatures
410
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
2 ACCEPTED SOLUTIONS
Community Beginner ,
Apr 17, 2025 Apr 17, 2025

Thanks for digging in to this!

 

I got a syntax error just copying and pasting but played with it and arrived at this:

 

var sigState = this.getField("Signature1").signatureValidate();

if (this.getField("Signature1").signatureInfo()<2)

{this.getField("Signature2").readonly = true; app.alert("Signature1 needs to be completed before you can sign here.")}

else

{this.getField("Signature2").readonly=false;}

 

I think it works! I can't test it very well because my own signature does actually validate successfully. I'll send it to the person with the invalid signature to test tomorrow! Thanks!

View solution in original post

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 ,
Apr 18, 2025 Apr 18, 2025

Hi @bread_6630 ,

 

1. The current process is too complicated for the workflow you want to achieve.

 There are also mistakes in the script's syntax, which is causing the syntax errors.

2. For instance, the "Signature Information" is an object that includes several properties like certificates, the signer's common name, security handler, email address, to name a few, and to include the validity status.

 

But your script is not referencing it correctly.

3. While checking the validity of a certificate-based digital signature is important, it might not be necessary for your particular workflow.

This is especially relevant since the validity of each signer's digital signature can be different.

A user might sign with a valid certificate, but their validity status in the certificate chain appears as "unknown".

As a result, the desired  actions of your current script are limited to the values defined in your conditional statement.

4. To make things a little easier,  below is a simple method that works well with signature fields signed using both self-signed certificate-based digital signatures and smart cards with a reader:

 

  • Open the Prepare Form Tool => open the Digital Signature Field properties dialog box of the event target signature field => go to the "Signed" tab => tick the box labeled: "This script executes when field is signed:" => and insert the script detailed below:

 

var f = event.target;
if (f.value == "<<dict>>") {this.getField("Signature2").readonly = false}

 

 

  • Then go to the "Actions" tab => set a Mouse Exit Action => add the following script line:

 

var f = event.target;
if (f.value !== "<<dict>>") {this.getField("Signature2").readonly = true}

 

I hope this helps.

View solution in original post

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 ,
Apr 17, 2025 Apr 17, 2025

Well, this is not something I've ever used before, but I think that signatureValidate() should return codes that will help you figure out what to have your script do for all of the possible states that the signature field might be in, right? 

 

Here's the relevant bit from the documentation

 

So .signatureValidate()==0 would just mean "blank or unsigned" but I think that it only means that once you've attempted to validate the signature field.  So why don't you first declare a variable that will let you look at the status of the sig field:

 

var sigState = this.getField("Signature1").signatureValidate();

 

and then step through your if statement

 

if (sigState < 2) {

{this.getField("Signature2").readonly = true; app.alert("Signature1 needs to be completed before you can sign here.")}

else

{this.getField("Signature2").readonly = false; }

 

I'm on my phone and have no way to test this, but that's my guess. 

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 Beginner ,
Apr 17, 2025 Apr 17, 2025

Thanks for digging in to this!

 

I got a syntax error just copying and pasting but played with it and arrived at this:

 

var sigState = this.getField("Signature1").signatureValidate();

if (this.getField("Signature1").signatureInfo()<2)

{this.getField("Signature2").readonly = true; app.alert("Signature1 needs to be completed before you can sign here.")}

else

{this.getField("Signature2").readonly=false;}

 

I think it works! I can't test it very well because my own signature does actually validate successfully. I'll send it to the person with the invalid signature to test tomorrow! Thanks!

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 ,
Apr 18, 2025 Apr 18, 2025

Hi @bread_6630 ,

 

1. The current process is too complicated for the workflow you want to achieve.

 There are also mistakes in the script's syntax, which is causing the syntax errors.

2. For instance, the "Signature Information" is an object that includes several properties like certificates, the signer's common name, security handler, email address, to name a few, and to include the validity status.

 

But your script is not referencing it correctly.

3. While checking the validity of a certificate-based digital signature is important, it might not be necessary for your particular workflow.

This is especially relevant since the validity of each signer's digital signature can be different.

A user might sign with a valid certificate, but their validity status in the certificate chain appears as "unknown".

As a result, the desired  actions of your current script are limited to the values defined in your conditional statement.

4. To make things a little easier,  below is a simple method that works well with signature fields signed using both self-signed certificate-based digital signatures and smart cards with a reader:

 

  • Open the Prepare Form Tool => open the Digital Signature Field properties dialog box of the event target signature field => go to the "Signed" tab => tick the box labeled: "This script executes when field is signed:" => and insert the script detailed below:

 

var f = event.target;
if (f.value == "<<dict>>") {this.getField("Signature2").readonly = false}

 

 

  • Then go to the "Actions" tab => set a Mouse Exit Action => add the following script line:

 

var f = event.target;
if (f.value !== "<<dict>>") {this.getField("Signature2").readonly = true}

 

I hope this helps.

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 ,
Apr 17, 2025 Apr 17, 2025

Is the script in "Signature2" field?

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 Beginner ,
Apr 17, 2025 Apr 17, 2025

Yes! It activates upon "mouse up" on the signauture 2 field.

 

It occurred to me that maybe making a script that ran upon the previous signature box being signed might have some advantage, but I hesitated to experiment with that since this is very nearly working.

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 ,
Apr 17, 2025 Apr 17, 2025

First, when calling the field that contains the script, use event.target not this.getField("Signature2").  Next, you said the default of the field is read only.  You can't run a mouse up action on a field set to read only.  Next, as soon as you click a Signature field, the mouse up action triggers the signing process before your mouse up script.  The signature process is going to run no matter what your mouse up script does.

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 ,
Apr 17, 2025 Apr 17, 2025

You can't run a mouse up action on a field set to read only.

@PDF Automation Station This is not entirely correct, for most fields it won't work, but you can use Mouse UP in Text, Date and Dropdown fields even if they are set to read only.

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 ,
Apr 18, 2025 Apr 18, 2025

As far as I know, read only means no interaction with mouse and the fields are skipped entirely when tabbing.

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 ,
Apr 18, 2025 Apr 18, 2025

I replicate that, and it works for me even when set to read only.

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 ,
Apr 18, 2025 Apr 18, 2025

That's strange.  Read only is supposed to be no interaction.  I have never been able to interact with the mouse on read only fields.  Tabbing skips fields set to read only and the cursor will not change from the hand when hovering.  I can't even get the tooltip to display.  It has always been like this for me since Acrobat 6.

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 ,
Apr 18, 2025 Apr 18, 2025

I see you use hand tool, I'm using arrow tool next to it.

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 ,
Apr 19, 2025 Apr 19, 2025
LATEST

I learned something new today.  Even with the arrow tool, read only fields are skipped when tabbing.

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 ,
Apr 17, 2025 Apr 17, 2025

Yes, the value property should work for that. It will return null if the field has no signature, or something else if it has (even if it's invalid).

Not sure this is a very good practice, but it should work...

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