Copy link to clipboard
Copied
hi, i'm having problem on how to auto-populate the drop down list (Wall Assignment) based on the Text box fields (Name). I am using Adobe Acrobat Pro Dc.
The table with Name column is from page 2, while the Wall Assignment drop down, is on page 3.
Whenever the user enters a Name, it will auto-populate the Wall Assignment list.
i saw some post that uses addItems and setItems, but still don't know what to use and where to insert the code. is it on the textbox using keystroke or action javascript, or on the drop down field.
thanks
Copy link to clipboard
Copied
All items in the dropdown are selectable. That is not the problem.
The issue is that this script is a calculation. The script is run anytime any field on the form changes.
There are 3 solutions:
1) Change the script to a validation script on the "LstGrp" text fields
2) Qualify the calculation by testing the source of the event. In this case it should be one of the "LstGrp" fields
3) (poor solution) Save the value of the list before changing the list items, then set it.
I think #2 is the best one since it blocks unnecessary updates and only changes code in one location.
Put the code in this if statement
if(/^LstGrp/.test(event.source.name))
{
.. The script...
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
there's a custom calculation script on the dropdown fields
if(/^LstGrp/.test(event.source.name))
{
//populate dropdown based on multiple textbox
var aValues = this.getField("LstGrp").getArray().map(function(a){return a.valueAsString;});
var aList = aValues.filter(function(a){return (a.length > 0);});
aList.unshift(" ");
event.target.setItems(aList);
}
then I add this to the reset button:
this.getField("ddWindowsWallAssignment").clearItems();
the list will only clear, if I enter and manually remove the data entered on the textbox
Copy link to clipboard
Copied
It's possible there are dueling scripts.
I think I said this in an earlier post, that setting the list items is unnecessary and problematic. That you should be setting the field value and locking the field with the "readonly" property when you want it locked down, rather than changing the items. Well now you're seeing the problem, erratic behavior. The easiest way to get the list field to show a blank on reset is to have a "blank" as one of the items, which is then set as the default value.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
i see. thanks anyway.
Copy link to clipboard
Copied
Hello Thom,
I successfully used this script on one set of fillable fields for a dropdown menu. I now would like to use it two more times in the same document for LstGrp1 and LstGrp2. In my limited experience in JavaScript, I would need to change the name of the variables, correct? I have an example below of what I believe the changes would be. Thank you for your insight.
if(/^LstGrp1/.test(event.source.name))
{
//populate dropdown based on multiple textbox
var bValues = this.getField("LstGrp1").getArray().map(function(b){return b.valueAsString;});
var bList = bValues.filter(function(b){return (b.length > 0);});
bList.unshift(" ");
event.target.setItems(bList);
}
Copy link to clipboard
Copied
Hi Thom, I have done the above and it works great. The only issue i come into now is if more items are added by the user to the LstGrp values, i.e. our 6 entries expand to 7, 8 or more, the already selected values from the dropdown disappear on previous pages. I have tried to lock down as read only, but the values are still removed if another listgroup item is added. Any suggestions?
Copy link to clipboard
Copied
Hello Jackson,
Whenever items are added or deleted from a list field, the selected values change and trigger events such as the "Change" event on the list field and calculation events in other fields on the form. To handle this issue, the offending events that cause the field values to disappear have to be identified first. Then blocking code needs to be added to make sure those values only change when they are supposed to. In fact, if the form has a complex web of inter-related events, then it would be a good idea to get handle on how these events are ordered. Then maybe do a bit of redesign to make the design as efficient and robust as possible.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
can you help me on this one? thanks
Copy link to clipboard
Copied
cool, will try that. thanks
another question, i have a two dropdown list. the entries on the second dropdown will depend on the item selected on the first dropdown.
example entries below:
dropdown1 - A, B, C, D
dropdown2 - 1, 2, 3, 4
if dropdown1 selects A, dropdown2 will have still 4 entries.
if dropdown1 selects B, dropdown2 will only have 1, 2 as entries.
if user selects blank or the form is reset, the entries on dropdown2 will be back at default.
how can I change the entries on dropdown2 based on the selection on dropdown1?
thanks
Copy link to clipboard
Copied
For this you'll need to use the custom keystroke event on dropdown1, And all dropdowns need to have the "commit selection immediately" option set.
if(event.willCommit)
{
switch(event.value)
{
case "A":
this.getField("dropdown2").setItems(.. list of items...);
break;
case "B":
this.getField("dropdown2").setItems(.. list of items...);
break;
}
}
Handling the form reset is a bit different. You'll need to put code on the reset button to set the list to the default set of items.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
will try these codes later.
thanks for the patience
Copy link to clipboard
Copied
thanks for the codes, i used this one so that the dropdown will also clear/reset whenever the textboxes are cleared
//populate dropdown based on multiple textbox
var aValues = this.getField("LstGrp").getArray().map(function(a){return a.valueAsString;});
var aList = aValues.filter(function(a){return (a.length > 0);});
event.target.setItems([" "].concat(aList));
Copy link to clipboard
Copied
Hey Thom, I know this is an old string, but your guidance saved me today - thanks for sharing your expertise.


-
- 1
- 2