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

toggle hide/show button for multiple fields and text

Community Beginner ,
Apr 02, 2021 Apr 02, 2021

var f = getField("group1");
f.display = display.visible;

 

I have come up with the above button JS to show a group of fields and text but am not sure what script to place in order for the button to toggle to hide the group.  Any suggestions would be appreciated.

TOPICS
JavaScript
3.7K
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
1 ACCEPTED SOLUTION
Community Expert ,
Apr 04, 2021 Apr 04, 2021

Try this code:

 

var allFields = this.getField("group1").getArray();
for (var i in allFields) {
	var f = allFields[i];
	f.display = (f.display==display.visible) ? display.hidden : display.visible;
}

View solution in original post

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
Enthusiast ,
Apr 02, 2021 Apr 02, 2021

"group1" is name of radio buttons? what fields do you have and what are their names?

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 03, 2021 Apr 03, 2021

Change this line:

f.display = display.visible;

To:

f.display = (f.display==display.visible) ?  display.hidden : 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 03, 2021 Apr 03, 2021

Sorry, I should have been clearer.  I have a number of fields (of different types) that I have grouped as group1.  These are all hidden and I would like to have them show and hide with the toggle of one button.

 

var f = getField("group1");
f.display = display.visible;

 

The above script shows them, I am not sure what needs to be added to then toggle the hide.

 

Thank you try67 for your reply.  I tried that script in the button but it didn't show the hidden fields.  Not sure why not?

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 03, 2021 Apr 03, 2021

Do you mean that some of these fields are hidden and some are visible, and you want to toggle the visibility of each one, independently of the others?

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 03, 2021 Apr 03, 2021

The group is either all hidden or all visible at the same time.  Ideally, the button select toggles this process.

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 04, 2021 Apr 04, 2021

Try this code:

 

var allFields = this.getField("group1").getArray();
for (var i in allFields) {
	var f = allFields[i];
	f.display = (f.display==display.visible) ? display.hidden : 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 04, 2021 Apr 04, 2021

Works like a charm.  Thank you very much.

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 04, 2021 Apr 04, 2021

What additional script would hide other groups (say group2, group3, group4) of fields?  I assume this would be placed before the showing of the group1 fields.

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 04, 2021 Apr 04, 2021
LATEST

Just duplicate the code, changing the field name in the first line.

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 03, 2021 Apr 03, 2021

Try code like this:

var f = getField("group1");
f.display = f.display == display.hidden ? display.visible : display.hidden;

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 03, 2021 Apr 03, 2021

Nope, it is still not working.  The below script:

 

var f = getField("group1");
f.display = display.visible;

 

still works to make the group1 items appear.  Neither:

 

var f = getField("group1");
f.display = f.display == display.hidden ? display.visible : display.hidden;

 

or

 

var f = getField("group1");

f.display = (f.display==display.visible) ? display.hidden : display.visible;

 

I appreciate your suggestions though.

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 03, 2021 Apr 03, 2021

Sorry, I didn't complete my reply. I meant to say that neither of the 2 suggestions worked.

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
Enthusiast ,
Apr 04, 2021 Apr 04, 2021

Nor did you explain what you need right. You can't group fields in acrobat. 

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 04, 2021 Apr 04, 2021

You can, by either giving them the same name, or by naming them using this pattern: GroupName.FieldName1, GroupName.FieldName2, etc., and since they mentioned they grouped fields of different types the latter is the only possible way.

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