Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Set fields read-only after signing with javascript

New Here ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

I have created a form with a button that adds a group of five text fields and one signature field to it. It is possible to add five groups. I want to make read-only all fields in a specific group after putting a signature in a signature field placed in the same group. Last hope in javascript because these fields don't exist until the button is pressed.

TOPICS
JavaScript, PDF forms

Views

74

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

If you want to make field read only after you signed signature field use script to make them readonly in Signed field->properties->signed tab (see photo):

Basic script to make read only:

this.getField("Field name").readonly = true;

Izrezak.PNG

Likes

Translate

Translate

Report

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
New Here ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

I can't do it this way, because there aren't any fields on the form until the button is pressed.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

Do you mean that you want to use JS to set the Signed action of the signature fields to lock certain fields?

If so, you can do is using the setLock method, like this:

 

this.getField("Signature1").setLock({ action: "Include", fields: ["Text1", "Text2", "Text3"] });

 

However, the fields you specify in the fields array have to actually exist when you set the action, or it will fail.

Likes

Translate

Translate

Report

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
New Here ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

I used the setLock method but it didn't work. I received an error: NotAllowedError: Security settings prevent access to this property or method. Field.setLock

I use Adobe Acrobat 2020

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

Did you run it in Acrobat or in Reader?

This is not the kind of method that you're supposed to use dynamically. You use it once and that's it.

I don't quite understand what you're trying to achieve, exactly...

Likes

Translate

Translate

Report

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
New Here ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

I don,t know why, but I can't post anything anymore here.

Likes

Translate

Translate

Report

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
New Here ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

var leftEdgePos = 10;
var topEdgePos = 700;
var rightEdgePos = 110;
var bottomEdgePos = 650;

this.addField("text1", "text", 0, [leftEdgePos, topEdgePos, rightEdgePos, bottomEdgePos]);

this.addField("text2", "text", 0, [leftEdgePos+100, topEdgePos, rightEdgePos+100, bottomEdgePos]);

this.addField("text3", "text", 0, [leftEdgePos+200, topEdgePos, rightEdgePos+200, bottomEdgePos]);

this.addField("text4", "text", 0, [leftEdgePos+300, topEdgePos, rightEdgePos+300, bottomEdgePos]);

this.addField("sign1", "signature", 0, [leftEdgePos+400, topEdgePos, rightEdgePos+400, bottomEdgePos]);

this.getField("sign1").setLock({ action: "Include", fields: ["text1", "text2", "text3", "text4"] });

Likes

Translate

Translate

Report

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
New Here ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

On the form there is only a button with mouse up event that execute the code above. As a result, five fields are added to the form and the following error message is displayed:

NotAllowedError: Security settings prevent access to this property or method. Field.setLock

Likes

Translate

Translate

Report

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
New Here ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

I apologize for the mess I made here. I forgot to write that I only use Adobe Acrobat Pro 2020

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

May be that you must use a trusted function for this.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

Yes, that's correct, it requires privileged context.

Likes

Translate

Translate

Report

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
New Here ,
Jul 29, 2021 Jul 29, 2021

Copy link to clipboard

Copied

LATEST

Considering what is written above, I have achieved my goal. The implementation of the function using the setLock method must be placed in the folder level script:

var setFieldLock = app.trustedFunction( function(field0, field1, field2, field3) {
	app.beginPriv();
	this.getField("sign1").setLock({ action: "Include", fields: [field0, field1, field2, field3] });
	app.endPriv();

The button event handler looks like this

var leftEdgePos = 10;
var topEdgePos = 700;
var rightEdgePos = 110;
var bottomEdgePos = 650;

this.addField("text1", "text", 0, [leftEdgePos, topEdgePos, rightEdgePos, bottomEdgePos]);

this.addField("text2", "text", 0, [leftEdgePos+100, topEdgePos, rightEdgePos+100, bottomEdgePos]);

this.addField("text3", "text", 0, [leftEdgePos+200, topEdgePos, rightEdgePos+200, bottomEdgePos]);

this.addField("text4", "text", 0, [leftEdgePos+300, topEdgePos, rightEdgePos+300, bottomEdgePos]);

this.addField("sign1", "signature", 0, [leftEdgePos+400, topEdgePos, rightEdgePos+400, bottomEdgePos]);

setFieldLock("text1", "text2", "text3", "text4");

Anyway this solution is useless for me because the document is no longer portable until the folder level script is placed locally on the user's computer.

Likes

Translate

Translate

Report

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