About the code to write to the drop-down list field.

Participant ,
May 07, 2020

Copy link to clipboard

Copied

I have set the items in the dropdown list as follows.

 

var l = this.getField("Dropdown1");
l.setItems(["One", "Two", "Three"]);

 

This will certainly show "One", "Two", "Three" in the drop down list.
However, when actually using it, for some reason only "One" can be selected.

Even if I select "Two", "One" is displayed.

 

I created a button for trial and wrote the code there.
In this case, it worked as planned.

 

Why can't I just write the code directly in the drop-down list?
Is it possible to achieve the goal without creating a new button?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

This kind of code only needs to execute once, or when the options change. When you use setItems it resets the field to the default value (the first item in the list), which is probably what is happening in your case.

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

334

Likes

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

About the code to write to the drop-down list field.

Participant ,
May 07, 2020

Copy link to clipboard

Copied

I have set the items in the dropdown list as follows.

 

var l = this.getField("Dropdown1");
l.setItems(["One", "Two", "Three"]);

 

This will certainly show "One", "Two", "Three" in the drop down list.
However, when actually using it, for some reason only "One" can be selected.

Even if I select "Two", "One" is displayed.

 

I created a button for trial and wrote the code there.
In this case, it worked as planned.

 

Why can't I just write the code directly in the drop-down list?
Is it possible to achieve the goal without creating a new button?

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

This kind of code only needs to execute once, or when the options change. When you use setItems it resets the field to the default value (the first item in the list), which is probably what is happening in your case.

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

335

Likes

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
May 07, 2020 1
Adobe Community Professional ,
May 07, 2020

Copy link to clipboard

Copied

Where in the dropdown list does you use the script?

Likes

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
Reply
Loading...
May 07, 2020 1
Participant ,
May 09, 2020

Copy link to clipboard

Copied

Where to enter the formula on the Options tab of the drop-down list field.

Likes

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
Reply
Loading...
May 09, 2020 0
Most Valuable Participant ,
May 08, 2020

Copy link to clipboard

Copied

This kind of code only needs to execute once, or when the options change. When you use setItems it resets the field to the default value (the first item in the list), which is probably what is happening in your case.

Likes

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
Reply
Loading...
May 08, 2020 3
Participant ,
May 09, 2020

Copy link to clipboard

Copied

The point is that what I want to do is impossible. I can understand what you say. Thank you very much.

Likes

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
Reply
Loading...
May 09, 2020 0
Most Valuable Participant ,
May 09, 2020

Copy link to clipboard

Copied

I don't know what you want to do, but that's not what I said...

Likes

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
Reply
Loading...
May 09, 2020 0
New Here ,
Jun 20, 2020

Copy link to clipboard

Copied

Hello try67.

 

I have the same problem here. And I don't know how to solve. Can you help me, please.

 

 

 

 

//Two checkbox
var a = getField("acessoAMagiasArcano").value;
var d = getField("acessoAMagiasDivino").value;

//One dropdown list just to help me with ".cleatItems()"
var c = getField("Classe").value;


var cM = '';

//My dropdown list "cML_01"
if(c == "Classe" || c == "  ") this.getField("cML_01").clearItems();


if(a == "No" && d == "No")  cM = '';

else{
	
	if(a == "Yes") cM = ["Círculo", "", "1º", "2º", "3º", "4º", "5º", "6º", "7º", "8º", "9º"];
	
	else if(d == "Yes") cM = ["Círculo", "", "1º", "2º", "3º", "4º", "5º", "6º", "7º"];

	else  cM = '';
	
}

if(cM != '') this.getField("cML_01").setItems(cM);

 

 

 

 

Then, I have two issues:

1º - The list only appears after I click on dropown. I saw that the solution is check the option "Commit selected value immediately". I already have this option cheked and doesn't work.

2º - The list is created as:

Círculo

 

 

When I click on "1º" (for example) my pdf take a long time loading then move back to "Círculo". Always. I have 17 equal fields, so I don't know how to use the dropdown "Classe" do populate my all 17 "cML" dropdow. 😞

Could you help me, please? 

 

cabeça_ramalho_0-1592702970604.pngcabeça_ramalho_1-1592702997641.pngcabeça_ramalho_2-1592703029796.pngcabeça_ramalho_3-1592703045200.pngcabeça_ramalho_4-1592703056184.png

 

Likes

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
Reply
Loading...
Jun 20, 2020 1