These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Show / Hide multiple fields?

rwilki
Registered: Oct 16 2009
Posts: 37

I have found a way to show hidden fields, but my problem is I need the script to:
 
1] show or add multiple sets of the hidden fields; and
2] have a remove button to remove extra fields that were accidentally added.
 
Basically, I am trying to display one set of multiple fields (7 total) with "add" button for the reader to add additional hidden field sets.
 
So my default visible set might be
 
text1, text2, text3, combobox4, listbox5, text6, text7
and I need several hidden sets named similarly
text1a, text2a, text3a, combobox4a, listbox5a, text6a, text7a
text1b, text2b, text3b, combobox4b, listbox5b, text6b, text7b
and so on...
 
I have this script working to display the first 7 fields, but I need my fields to be in groups or sets and I cannot figure out how to get it to display another set upon clicking the button.
 
var lst_dynamicFld = this.getField("text1");
var secondField = this.getField("text2");
var thirdField = this.getField("text3");
var fourthField = this.getField("combobox4");
var fifthField = this.getField("listbox5");
var sixthField = this.getField("text6");
var seventhField = this.getField("text7");

if (event.target.value == "No") {
lst_dynamicFld.display = display.hidden;
secondField.display = display.hidden;
thirdField.display = display.hidden;
fourthField.display = display.hidden;
fifthField.display = display.hidden;
sixthField.display = display.hidden;
seventhField.display = display.hidden;
}
else {
lst_dynamicFld.display = display.visible;
secondField.display = display.visible;
thirdField.display = display.visible;
fourthField.display = display.visible;
fifthField.display = display.visible;
sixthField.display = display.visible;
seventhField.display = display.visible;
}
 
Any ideas?

My Product Information:
Acrobat Pro 9.4.3, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2398
If you're looking to dynamically add or remove fields from the form, a LiveCycle form is more suited for that.
It is possible to do it in an AcroForm, but it will require quite a bit of scripting, plus you will not be able to automatically generate new pages to place the fields on or to push various objects to make room for the new fields.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

rwilki
Registered: Oct 16 2009
Posts: 37
try67 wrote:
If you're looking to dynamically add or remove fields from the form, a LiveCycle form is more suited for that.
It is possible to do it in an AcroForm, but it will require quite a bit of scripting, plus you will not be able to automatically generate new pages to place the fields on or to push various objects to make room for the new fields.
Thanks for your reply. I didn't think I was looking at a dynamic approach and I can't go the LiveCycle method. The script I've found seems to work fine for adding multiple fields individually. But, I'd like it to be able to add them in sets. So, if my button is clicked, it adds set 1, if clicked again, it adds set 2 after set 1, etc... The hidden fields can have their names hard coded because I have a finite number of these "sets" to appear as a cap.

I feel like I'm close but maybe I'm not. The reason I added the example of my code was to see if there was a way to combine the fields in an array so that in this example

var lst_dynamicFld = this.getField("text1") the first field might include "text1","text2","text3", etc...

The verbiage dynamicFld came from a script, I'm not sure if that's necessary or not...


try67
Expert
Registered: Oct 30 2008
Posts: 2398
So are those fields already existing in your file, or do you want to create them (add them) when the button is clicked?
Basically, I would recommend using a different naming scheme (with numbers instead of letters), so you could easily check which fields exist/are visible using a loop.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

rwilki
Registered: Oct 16 2009
Posts: 37
try67 wrote:
So are those fields already existing in your file, or do you want to create them (add them) when the button is clicked?
Basically, I would recommend using a different naming scheme (with numbers instead of letters), so you could easily check which fields exist/are visible using a loop.
Yes, these are existing fields within my file. The naming is a good idea, I'm just not sure how to create this loop so that when the button is clicked the first time, fieldset 1 appears, when clicked again, fieldset 2 appears, up to the last predefined set.

Thanks...
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Let's say the fields are called "field1", "field2", etc.
You can use something like this:

  1. var f = getField("field1");
  2. var i = 1;
  3. while (f!=null && f.display == display.visible) {
  4. i++;
  5. f = getField("field"+i);
  6. }
At the end of this loop, f will be the first field which is not visible (or null, if all of the fields with that name pattern are visible).

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

rwilki
Registered: Oct 16 2009
Posts: 37
wow I thought that would work, but it didn't. Doesn't show any of the fields. I'm using your test code as javascript with button "mouse - down" event. thanks for your time.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
The code I gave you by itself doesn't change anything. You need to use the f variable after the loop to do what you want, for example to show it.

Did you adjust the names of the fields in the script to match the ones in your file?
Are there any error messages?

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

rwilki
Registered: Oct 16 2009
Posts: 37
thanks. I understand what you're saying in concept but I don't know how to apply it. I might just use this code below, for each of my sets of fields and just put a checkbox at the end of each set.

var nHide = event.target.isBoxChecked(0)?display.visible:display.hidden;
this.getField("field1").display = nHide;
this.getField("field2").display = nHide;
this.getField("field3").display = nHide;

thanks,
Bob