Skip to main content
Inspiring
May 7, 2020
Answered

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

  • May 7, 2020
  • 2 replies
  • 1323 views

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?

This topic has been closed for replies.
Correct answer try67

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.

2 replies

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 8, 2020

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.

cabeça_ramalho
New Participant
June 21, 2020

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? 

 

 

Bernd Alheit
Community Expert
Community Expert
May 8, 2020

Where in the dropdown list does you use the script?

Inspiring
May 9, 2020

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