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

Make checkboxes hidden/visible for 22 fields with same parent name

Community Beginner ,
Apr 23, 2025 Apr 23, 2025

 

I have a form that have fields: "Normal", "NotPresent", "P", "S".

The are all named as Normal1, Normal2, Normal3, etc until Normal22 and same for the other fields.

Right now I have written the ame code in each of the checkboxes, but when I need to make a change I would have to go to each 22 fields to make the change.

 

This the code for Normal1:

if(event.target.value ==(0)) {

getField("Normal1").required = false;
getField("NotPresent1").required = false;
getField("P1").required = false;
getField("S1").required = false;

this.getField("NotPresent1").display = display.hidden;
this.getField("P1").display = display.hidden;
this.getField("S1").display = display.hidden;

} else {

getField("Normal1").required = true;
getField("NotPresent1").required = true;
getField("P1").required = true;
getField("S1").required = true;

this.getField("NotPresent1").display = display.visible;
this.getField("P1").display = display.visible;
this.getField("S1").display = display.visible;
}

 

How do I make it go through Normal22 with the same code?

338
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 23, 2025 Apr 23, 2025

What are the names of the check-boxes?

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

They are all checkboxes. When Normal is checked off, it returns a value of "0".

All I want is to have the other checkboxes hidden when the test is Normal.

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

I understood that, but if you want the code to all be located in a single location, so you could easily edit it, it needs to contain the actual field names of those fields. So what are they?

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

They are:

Normal1, Normal2, Normal3. [...], Normal22

NotPresent1, NotPresent2, NotPresent3 [...], NotPresent22

P1, P2, P3 [...], P22

S1, S2, S3, [...], S22

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

No, these are the fields you want the check-boxes to influence. But that are the names of those check-boxes themselves?

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

I am not sure I understand. They are the actual names of the check boxes. 

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

So clicking Normal1 changes its own Required property? That doesn't make sense...

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

Anyway, you can do it using this code as a doc-level script, and then just call the function from the MouseUp event of each of the Normal fields:

 

function mouseUpNormal() {
    var fieldName = event.target.name.replace("Normal", "");
    if (event.target.value=="Off") {

        this.getField("Normal" + fieldName).required = false;
        this.getField("NotPresent" + fieldName).required = false;
        this.getField("P" + fieldName).required = false;
        this.getField("S" + fieldName).required = false;

        this.getField("NotPresent" + fieldName).display = display.hidden;
        this.getField("P" + fieldName).display = display.hidden;
        this.getField("S" + fieldName).display = display.hidden;

    } else {

        this.getField("Normal" + fieldName).required = true;
        this.getField("NotPresent" + fieldName).required = true;
        this.getField("P" + fieldName).required = true;
        this.getField("S" + fieldName).required = true;

        this.getField("NotPresent" + fieldName).display = display.visible;
        this.getField("P" + fieldName).display = display.visible;
        this.getField("S" + fieldName).display = display.visible;
    }
}

 

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

When opening the form, all the checkboxes are required. For the first row, you have to either choose Normal, NotPresent, P or S. Once any checkbox is clicked, then I want to remove the red around all the checkboxes, so the user don't need to pay attention to the other checkboxes on that row.

Clicking Normal1 will remove the requiredness of itself and the other checkboxes.

If Normal1 is unclicked, then it will add back the requiredness of all the other checkboxes. 

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

OK, I think I understand it now. See the code I posted above.

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

Thank you it works.

I tried to use the same logic for the P checkbox, but it doesn't work probably because it has 3 checkboxes with value of 1, 2, and 3.

How should I change this statement 

if (event.target.value=="Off")

.

I tried 

if (event.target.value=="Off")

or

if((event.target.value ==(1)) || (event.target.value ==(2)) || (event.target.value ==(3)))

But it doesn't do anything.

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

I don't follow what you're trying to do. Did you use my code?

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

[MOVED TO THE ACROBAT DISCUSSIONS]


Acrobate du PDF, InDesigner et Photoshoptographe
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 27, 2025 Apr 27, 2025
LATEST

If I understand correctly, the intended behavior is as follows:

  • When one checkbox in a row is checked, that checkbox remains visible and not required, while the other checkboxes in the same row are set to hidden and not required.

  • If none of the checkboxes in a row are checked, all checkboxes in that row become visible and required.

This logic should apply consistently across all rows?

You can remove other script and place this script as custom calculation script in one text field (it can be hidden):

for (var i=1; i<=22; i++) {
 var fields = [
  this.getField("Normal" + i),
  this.getField("NotPresent" + i),
  this.getField("P" + i),
  this.getField("S" + i)
 ];

 var active = -1;
 for (var j=0; j<fields.length; j++) {
  if (fields[j].valueAsString !== "Off") {
   active = j;
   break;}}

 for (var j=0; j<fields.length; j++) {
  if (active !== -1) {
   fields[j].required = false;
   fields[j].display = (j === active) ? display.visible : display.hidden;} 
  else {
   fields[j].required = true;
   fields[j].display = display.visible;}}}
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