toggle hide/show button for multiple fields and text

Community Beginner ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

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

Views

354

Likes

Translate

Translate

Report

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

correct answers 1 Correct Answer

Adobe Community Professional , 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; }

Likes

Translate

Translate
Engaged ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Change this line:

f.display = display.visible;

To:

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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?

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Works like a charm.  Thank you very much.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Try code like this:

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

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