Copy link to clipboard
Copied
Hello i am new to this field of PDF forms and I wanted to do something "simple" but it turns out i have no idea how.
I have a file with which starts with a combo field and it autofills several boxes after it. I want to add an option to the combo field to ADD another text box after the final so the last person can add additional information. Is it even possible?
(i have attached a quick mockup, not currently on my work PC so i cant show the original)
Copy link to clipboard
Copied
You need to create that field in advance and show/hide it based on the user's selection in the drop-down.
As the custom calculation script of the text field enter:
event.target.display = ? (this.getField("Dropdown1").value=="test 2") ? display.visible : display.hidden;
Copy link to clipboard
Copied
That is actually quite ingenious, would not have thought of it! Thank you. This potentially works with other objects i am assuming so this is wonderful!
Copy link to clipboard
Copied
Yes, it can work with any other field or comment (although the latter is more complicated to set up).
Copy link to clipboard
Copied
ok sorry for carrying on with the questions but i don't quite get the "?"
I did try it and nothing really happened
(again, sorry for the snapshots, not exactly in proper working condition atm)
Copy link to clipboard
Copied
Why did you use "hide" instead of the actual value "Not_Here"?
The question mark operator is short-hand for if-else. The first statement after it is executed when the condition is true, the second one (after the colon) if it's false.
Copy link to clipboard
Copied
sorry for the late response, because i put the output as "hide" it all worked! Thank you very much!
But i have a follow up question. Since i am applying this to several different boxes can i somehow group them in a separate skript?
so for example to geoup boxes 1,2 and 4 and to give them different values/visibility depending on the combo menu?
Copy link to clipboard
Copied
Just duplicate the code for each field.
Copy link to clipboard
Copied
I was afraid of that 🙂
Currently i am on field 150 and most likely will go to 400+
But it is what it is
Copy link to clipboard
Copied
Ah ok, in that case there are other options available. You can use a single calculation script for all of them, and you can group fields that needs to work the same way into an array. For example:
var fieldsGroup1 = ["Checkbox1", "Checkbox2", "Text1", "Dropdown4"];
for (var i in fieldsGroup1) {
var f = this.getField(fieldsGroup1[i]);
f.display = ? (this.getField("Dropdown1").value=="test 2") ? display.visible : display.hidden;
}
Copy link to clipboard
Copied
Hi,
So i've been still struggling with this and for some reason it doesn't work.
I have taken a different approach and it somewhat works..
I changed the formating of the combo box to this:
if ( event.willCommit)
{
if (event.value == " ")
this.getField("a").display = display.hidden;
else
this.getField("a").display = display.visible;
}
if ( event.willCommit)
{
if (event.value == "1")
f.display = display.hidden;
else
f.display = display.visible;
}
And have added a script in the document as such:
var boxes = ['b', 'c', 'd'];
for (var i in boxes)
{
var f = this.getField(boxes[i]);
}
and the reuslt right now is: if value of combo is " " only box a is hidden, if value is "1" only box d is hidden, and honestly i do not know why.
Can i just say somehow that f=all boxes from the set variable "boxes"
Copy link to clipboard
Copied
Hello again, if someone is interested i managed to solve my "problem". I followed the logic in this question:
and just renamed all of my boxes according to the groups name and it worked like a charm
e.g.: trial.a, trial.b, option.a, option.b etc
Thank you all for your help
Copy link to clipboard
Copied
Hi again, I am pushing forward with my form file and have stumbled uppon another issue. I have several boxes that do calculations regardsing diferent boxes e.g:
event.value = this.getField("text_box").value * 2
and was wodnering is there an automated way if i change the "text_box" name to smt else "item_quantity" can it update in the calculations as well?
Copy link to clipboard
Copied
No, you have to change it yourself. That's why it can be helpful to perform all the calculations from a single field, as it allows you do a search&replace command on your entire code at once.