Skip to main content
NateW81881
Known Participant
January 21, 2024
Answered

Locking part of a form

  • January 21, 2024
  • 3 replies
  • 1890 views

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

This topic has been closed for replies.
Correct answer Nesa Nurani

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.


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;}}}

3 replies

NateW81881
Known Participant
January 22, 2024

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

try67
Community Expert
January 21, 2024

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?

NateW81881
Known Participant
January 21, 2024

Yes, I want to be able to toggle the fields on the first two pages as needed between read-only and editable.

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
January 22, 2024

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.


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;}}}
Inspiring
January 21, 2024

Where do you use script?

If it's a button, will that button be on one of the first two pages?

NateW81881
Known Participant
January 21, 2024

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.