Copy link to clipboard
Copied
long-time reader, first-time poster. I will be the first to admit that I'm over my head. Here is the Reader's Digest version, my employer has tasked me with remaking all our forms and turning them into interactive PDFs. Most of the forms are pretty straightforward and I have had little issues. The main form is currently 4 pages with information from the first two pages populating information on the last two. I have come up with this after many searches:
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if ((typeof f.page=="number" && f.page==0) || (typeof f.page=="object" && f.page.indexOf(0)!=-1)) f.readonly = true; // makes only fields on page 1 readonly
}
I don't remember exactly which posts helped but Try67 and a few others have answered similar questions with variations of the above script and that helped. This script made the first page of the original 3-page version of the form read-only but now they would like it to be able to turn on and off the read-only for the first two pages. Any help would be appreciated.
Nate
Copy link to clipboard
Copied
Use this in checkbox:
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if(f.name !== event.target.name) {
if((typeof f.page === "number" && (f.page === 0 || f.page === 1)) || (typeof f.page === "object" && (f.page.indexOf(0) !== -1 || f.page.indexOf(1) !== -1))) {
f.readonly = event.target.value === "Off" ? false : true;}}}
Copy link to clipboard
Copied
Where do you use script?
If it's a button, will that button be on one of the first two pages?
Copy link to clipboard
Copied
I was thinking of using the script with a checkbox on either page one or two, preferably page one. What I'm trying to do is make it harder to accidentally change information on the first two pages. The first two sheets are used by the office with the customer while figuring out what they want for their cabinets and it can change multiple times before things are finalized, and can even change while the cabinets are being built, the last two are to be used by the rest of the shop.
Copy link to clipboard
Copied
So you want to toggle all fields at the same time (ie. change their state from the current one to the opposite), or to set them all as read-only or as editable?
Copy link to clipboard
Copied
Yes, I want to be able to toggle the fields on the first two pages as needed between read-only and editable.
Copy link to clipboard
Copied
Try this code:
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if ((typeof f.page=="number" && (f.page==0 || f.page==1)) || (typeof f.page=="object" && (f.page.indexOf(0)!=-1 || f.page.indexOf(1)!=-1)))
f.readonly = !f.readonly;
}
Copy link to clipboard
Copied
Since it will be a toggle, you should also add condition to not set field (checkbox) to read only in which is script used since checkbox will be used in one of the pages that will be set to read only.
Copy link to clipboard
Copied
I saw a script that you posted a few days ago that allows for the toggle but for all pages. I'm still lost on how to make this work.
Copy link to clipboard
Copied
Use this in checkbox:
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
var f = this.getField(fname);
if(f.name !== event.target.name) {
if((typeof f.page === "number" && (f.page === 0 || f.page === 1)) || (typeof f.page === "object" && (f.page.indexOf(0) !== -1 || f.page.indexOf(1) !== -1))) {
f.readonly = event.target.value === "Off" ? false : true;}}}
Copy link to clipboard
Copied
I think I see where i was going wrong. When I would change the script I was locking the last two pages, then I would attempt something else and part of the front page would disappear. Thank you for your help. It works beautifully.
Copy link to clipboard
Copied
so this script makes the first two pages read-only but will not allow it to go back to editable. I have tried this code
for(var i = 0; i < this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if(f.name !== event.target.name){
if(event.target.value == "Off")
f.readonly = false;
else
f.readonly = true;}}
by Nesa Nurani from the discussion "Script to lock all editable fields in PDF, then deletes the "Lock" button." This script allows for the turning on and off the read-only. I have tried some variations of the two scripts with little success.
Copy link to clipboard
Copied
I would like to thank try67 and Nesa Nurani for their help. They were both extremely helpful and came up with the solution to a problem I have been working on for a few weeks, should have asked for help sooner but was trying to learn (pretty stubborn). Thank you again