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

How to auto add values from text fields to Combo Box/Dropdown list?

Community Beginner ,
Jul 05, 2020 Jul 05, 2020

Copy link to clipboard

Copied

On my PDF I have three Email Address text fields - when a value is entered into one of these fields I would like the entered value to automatically be added to a combo box to allow the user to select which email address they would like to use to receive correspondence. 

 

So far I have the following code added to the combo box: 

 

 

var emailList = [" "];

if(this.getField("EmailAddress1").value) {
emailList.push([this.getField("EmailAddress1").value]);
}

if(this.getField("EmailAddress2").value) {
emailList.push([this.getField("EmailAddress2").value]);
}

if(this.getField("EmailAddress3").value) {
emailList.push([this.getField("EmailAddress3").value]);
}

this.getField("PortfolioCorrespondenceEmail1").clearItems();
this.getField("PortfolioCorrespondenceEmail1").setItems(emailList);

 

 

 

 

This code does return the values as hoped, however, I am required to click in the dropdown to refresh the values in the list, this may give the impression to users that there are no emails available for selection as initially there is just a " " option until the values are loaded into the list.

 

I have selected "commit selected value immediately" but it doesn't seem to fix the problem. At the moment I have no code in the custom keystroke, I am wondering whether there is something I should add in there?

 

Update: I have since moved the code into the custom calculation area and the dropdown list options are populating immediately, however it won't let me select one of the options. When I select one of the options it just looks like the list is reloading and the option doesn't select. 

 

TOPICS
Acrobat SDK and JavaScript

Views

1.4K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jul 06, 2020 Jul 06, 2020

Honestly this is all you need:

 

var f = event.target;
var emailList = [event.value,""];

if(this.getField("a").value) {emailList.push([this.getField("a").value]);} 

if(this.getField("b").value) {emailList.push([this.getField("b").value]);} 

if(this.getField("c").value) {emailList.push([this.getField("c").value]);}


f.setItems(emailList);

 

You can run it as custom calculation script and also as custom format script.

 

It updates on real-time and if the user deletes the other two email and decides

...

Votes

Translate

Translate
Community Expert ,
Jul 06, 2020 Jul 06, 2020

Copy link to clipboard

Copied

Honestly this is all you need:

 

var f = event.target;
var emailList = [event.value,""];

if(this.getField("a").value) {emailList.push([this.getField("a").value]);} 

if(this.getField("b").value) {emailList.push([this.getField("b").value]);} 

if(this.getField("c").value) {emailList.push([this.getField("c").value]);}


f.setItems(emailList);

 

You can run it as custom calculation script and also as custom format script.

 

It updates on real-time and if the user deletes the other two email and decides to delete the third entry, clicking on the empty item of the drop down menu clears the box.

 

 

Votes

Translate

Translate

Report

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 ,
Jul 07, 2020 Jul 07, 2020

Copy link to clipboard

Copied

LATEST

Thanks for the help guys. Got it working as hoped now, appreciate the time you spent helping me. 

Votes

Translate

Translate

Report

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