Skip to main content
Ren Sukhram
Known Participant
September 1, 2020
Answered

Reset button changes field read only option

  • September 1, 2020
  • 1 reply
  • 3352 views

So working on this form and the intention is to keep sub-sections read only unless the main section is checked off.  It works but if I hit the clear button after enabling those sub-section fields change to non-read-only (not sure what you would call that).

 

main section checkbox is using this JS script:

 

if (this.getField("IL-CHECK").value=="Off") {
this.getField("IL-BK").readonly = true;
this.getField("IL-CL").readonly = true;
this.getField("IL").readonly = true;
this.getField("IL-OTHER").readonly = true;
this.getField("IL-BK-OVG").readonly = true;
this.getField("IL-CL-OVG").readonly = true;
this.resetForm(["IL-BK", "IL-CL", "IL", "IL-OTHER", "IL-BK-OVG", "IL-CL-OVG"]);
} else {
this.getField("IL-BK").readonly = false;
this.getField("IL-CL").readonly = false;
this.getField("IL").readonly = false;
this.getField("IL-OTHER").readonly = true;
this.getField("IL-BK-OVG").readonly = false;
this.getField("IL-CL-OVG").readonly = false;
}

 

and sub-section checkboxes are using this:

 

if (this.getField("IL").value == "3") 
{
    this.getField("IL-OTHER").readonly = false;
} 
else
{
    this.resetForm(["IL-OTHER"]);
    this.getField("IL-OTHER").readonly = true;
}

 

 

This topic has been closed for replies.
Correct answer Thom Parker

The form reset only affects field values, it doesn't reset the read-only property.  What you need to do is add a script to the "Clear" button. Buttons can run more than one action so you can have both the Reset and the "Run a JavaScript" together. Copy the code for restting the readOnly values into this script.

 

You might also consider using Group Naming to make these form handling operations easier. 

For example "IL.Other" "IL.BK-OVG" , Now you can reset the values and the readOnly like this

 

this.getField("IL").readonly = true;

this.resetForm("IL");

 

 

1 reply

Thom Parker
Community Expert
Thom ParkerCommunity ExpertCorrect answer
Community Expert
September 1, 2020

The form reset only affects field values, it doesn't reset the read-only property.  What you need to do is add a script to the "Clear" button. Buttons can run more than one action so you can have both the Reset and the "Run a JavaScript" together. Copy the code for restting the readOnly values into this script.

 

You might also consider using Group Naming to make these form handling operations easier. 

For example "IL.Other" "IL.BK-OVG" , Now you can reset the values and the readOnly like this

 

this.getField("IL").readonly = true;

this.resetForm("IL");

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Ren Sukhram
Known Participant
September 1, 2020

Thom, totally seperate but from the code above you can see I am using a checkbox to enable and diable text fields. 

 

I have 3 sections doing the same behavior.  I was looking at an example you posted about using checkboxes as radio buttons (because you can uncheck a checkbox) but im having difficulty figuring out make it work.

 

So if you look at the text doc pdf i posted orginally these 3 sections enable the fields (INCLUDED IN LEASE, BILLED SEPERATELY, WIDE FORMAT).  How would I maintain the same function using your approach to checkboxes being used as radio buttons.

 

Thanks again.

 

Ren Sukhram
Known Participant
September 1, 2020

The current code tests for an "Off" state. This is the prefered method for checkboxes because it works regardless of export value.

However, for radio buttons you need to test for the actual export value, and reverse the order of the code blocks. 

 

For example:

if (this.getField("MA").value=="1") {
this.getField("IL-BK").readonly = false;
this.getField("IL-CL").readonly = false;
this.getField("IL").readonly = false;
this.getField("IL-OTHER").readonly = true;
this.getField("IL-BK-OVG").readonly = false;
this.getField("IL-CL-OVG").readonly = false;
} else {
this.getField("IL-BK").readonly = true;
this.getField("IL-CL").readonly = true;
this.getField("IL").readonly = true;
this.getField("IL-OTHER").readonly = true;
this.getField("IL-BK-OVG").readonly = true;
this.getField("IL-CL-OVG").readonly = true;
this.resetForm(["IL-BK", "IL-CL", "IL", "IL-OTHER", "IL-BK-OVG", "IL-CL-OVG"]);
}

 

 


So the only issue I see is when going from checkbox MA1 to MA2 all of MA1's content is still enabled.  The only way to disable MA1's content is to uncheck MA1 directly and deselect using MA2 while MA1 is selected.

 

also would MA2's first line of code be?

if (this.getField("MA").value=="2") {