Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to populate drop down list based on multiple text box entries

Community Beginner ,
Feb 23, 2019 Feb 23, 2019

dropdown.png

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

TOPICS
PDF forms
16.6K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Feb 28, 2019 Feb 28, 2019

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...

}

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

View solution in original post

Translate
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 ,
Mar 04, 2019 Mar 04, 2019

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

Translate
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 Expert ,
Mar 04, 2019 Mar 04, 2019

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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Mar 04, 2019 Mar 04, 2019

i see. thanks anyway.

Translate
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
New Here ,
Jul 27, 2022 Jul 27, 2022

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

Translate
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
New Here ,
Sep 21, 2022 Sep 21, 2022

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? 

Translate
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 Expert ,
Sep 27, 2022 Sep 27, 2022
LATEST

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.  

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Feb 24, 2019 Feb 24, 2019

George_Johnson​

can you help me on this one? thanks

Translate
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 ,
Feb 26, 2019 Feb 26, 2019

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

Translate
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 Expert ,
Feb 26, 2019 Feb 26, 2019

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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Translate
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 ,
Feb 26, 2019 Feb 26, 2019

will try these codes later.

thanks for the patience

Translate
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 ,
Feb 28, 2019 Feb 28, 2019

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

Translate
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
New Here ,
Aug 13, 2020 Aug 13, 2020

Hey Thom,  I know this is an old string, but your guidance saved me today - thanks for sharing your expertise.  

Translate
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