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.
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;
}
Copy link to clipboard
Copied
"group1" is name of radio buttons? what fields do you have and what are their names?
Copy link to clipboard
Copied
Change this line:
f.display = display.visible;
To:
f.display = (f.display==display.visible) ? display.hidden : display.visible;
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?
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?
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.
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;
}
Copy link to clipboard
Copied
Works like a charm. Thank you very much.
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.
Copy link to clipboard
Copied
Just duplicate the code, changing the field name in the first line.
Copy link to clipboard
Copied
Try code like this:
var f = getField("group1");
f.display = f.display == display.hidden ? display.visible : display.hidden;
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.
Copy link to clipboard
Copied
Sorry, I didn't complete my reply. I meant to say that neither of the 2 suggestions worked.
Copy link to clipboard
Copied
Nor did you explain what you need right. You can't group fields in acrobat.
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.