Skip to main content
pbmzbr
Participating Frequently
June 21, 2020
Answered

Acrobat Pro DC - Dropdown list always keeps the first item on the list instead of the selected item

  • June 21, 2020
  • 2 replies
  • 4745 views

Hello, community. 🙂

 

I am creating a fillable form with some calculation and dependent options.

But, I am encountering some problems. I already searched Google, here in the forum (in all topics related to dropdown), stack overflow ... And I still couldn't solve it.

The first problem, and the most annoying: I create a dropdown that is dependent on the values ​​of other 3 dropdown lists, and that changes its content according to the choices of the previous dropdowns.
I managed to generate the dropdown, with great difficulty, but when I click on an option, it does not keep the selected item, showing only the first item in the list.

The second problem is that the list items only appear after I click on the dropdown and not before. It is blank / empty and, after I click it, it displays the result.

I already checked the option to commit immediately after choosing, however, this did not solve the problem.

I read, in another topic, that the "setItem ()" method is not the most suitable, but I only know the setItem and addItem and the most indicated, it seems to me, is the setItem.

 

So, the first dropdown is "Classe", the second is "Nível" and the third is "Tendência", and the "problematic" dropdow is "especializacao" (NOT the "Especialização" « that one is independent and static).

 

CLASSE

NÍVEL

 

TENDÊNCIA

 

ESPECIALIZACAO

 

 

The script

Format - Custom - Custom Format Script

 

 

 

 

 

 

 

 

 

 

//Format - Custom - Custom Format Script
var c = getField("Classe").value;
var n = getField("Nível").value;
var t = getField("Tendência").value;
var esp = this.getField("especializacao");

var e;

if(c == "Classe" || c == "  " || n == "Nível" || n == "  " || n < 5 || t == "Tendência" || t == "  "){
	e = '';
	this.getField("especializacao").clearItems();
}

else{
	
	if(c == "Ladrão") e = ["Especialização", "Ranger", "Bardo", "Assassino"];
	
	else if(c == "Clérigo"){ 
		if(t == "Caótica") e = ["Especialização", "Druída", "Caçador", "Ocultista"];
		else e = ["Especialização", "Druída", "Caçador"];
	}
	
	else if(c == "Homem de Armas"){
		if(t == "Ordeira") e = ["Especialização", "Paladino", "Guerreiro", "Bárbaro"];
		else e = ["Especialização", "Guerreiro", "Bárbaro"];
	}
		
	else if(c == "Mago"){
		if(t == "Caótica") e = ["Especialização", "Ilusionista", "Adivinhador", "Necromante"];
		else e = ["Especialização", "Ilusionista", "Adivinhador"];
	}
	
	else e = '';
		
}

esp.commitOnSelChange = true;
esp.setItems(e);

 

 

 

 

 

 

 

 

 

 

 

Format - Custom - Custom Keystroke Script

 

 

 

 

 

 

 

 

 

 

 

//Format - Custom - Custom Keystroke Script

if( event.willCommit ){

	if(event.value === '') this.getField("especializacao").clearItems();
	else SetFieldValues(event.value);

}

 

 

 

 

 

 

 

 

 

 

 

Here the dropdown "working"

 

Still ... It takes 3 minutes to load for nothing and, in the end, I only have the first option on the list instead of the entire list.

 

By the way: it is necessary to display the choice from the list, it must be possible to change the choice, and if the "Nível" drops from 5, the dropdown should be empty again.
And, to make my situation worse, the result of this dropdown will fill a field.

 

Update: Working code

 

var c = getField("Classe").value;
var n = getField("Nível").value;
var t = getField("Tendência").value;
var esp = this.getField("especializacao");

if (event.source && (event.source.name=="Classe" || event.source.name=="Nível" || event.source.name=="Tendência")) {

	this.getField("especializacao").clearItems();

	if(c == "Ladrão" && n > 4) esp.setItems([["Especialização", "esp"],["  ","  "],["Ranger", "ran"],["Bardo", "bar"],["Assassino", "ass"]]);
	
	else if(c == "Clérigo" && n > 4){ 
		if(t == "Caótica") esp.setItems([["Especialização", "esp"],["  ","  "],["Druída", "dru"],["Caçador", "cac"],["Ocultista", "ocu"]]);
		
		else if(t == "Ordeira" || t == "Neutra") esp.setItems([["Especialização", "esp"],["  ","  "],["Druída", "dru"],["Caçador", "cac"]]);
		
		else this.getField("especializacao").clearItems();
	}
	
	else if(c == "Homem de Armas" && n > 4){
		if(t == "Ordeira") esp.setItems([["Especialização", "esp"],["  ","  "],["Paladino", "pal"],["Guerreiro", "gue"],["Bárbaro", "brb"]]);
		
		else if(t == "Neutra" || t == "Caótica") esp.setItems([["Especialização", "esp"],["  ","  "],["Guerreiro", "gue"],["Bárbaro", "brb"]]);
		
		else this.getField("especializacao").clearItems();
	}
		
	else if(c == "Mago" && n > 4){
		if(t == "Caótica") esp.setItems([["Especialização", "esp"],["  ","  "],["Ilusionista", "ilu"],["Adivinhador", "adi"],["Necromante", "nec"]]);
		
		else if(t == "Ordeira" || t == "Neutra") esp.setItems([["Especialização", "esp"],["  ","  "],["Ilusionista", "ilu"],["Adivinhador", "adi"]]);
		
		else this.getField("especializacao").clearItems();
	}
	
	else this.getField("especializacao").clearItems();
	
}

 



For mor information look the comments below and the attached PDF. 🙂

This topic has been closed for replies.
Correct answer try67

I'm sorry, but now I don't understand what I need to do.
Can you share an example with me, please?

 

In time: I updated the attached PDF file.


Surround the code with this:

if (event.source && (event.source.name=="Classe" || event.source.name=="Nível"
|| event.source.name=="Tendência")) {

// rest of code goes here

}

2 replies

pbmzbr
pbmzbrAuthor
Participating Frequently
June 26, 2020

Thank you very much @try67 for all the help given to help me solve my problem.

I updated the PDF with the proposed solution applied and working. 🙂

try67
Community Expert
Community Expert
June 21, 2020

A couple of notes:

- There is no setItem method. I think you mean setItems.

- The parameter you supply to this method must be an array, not a string.

- I would use the Validation event, instead of the Format event.

- Make sure the option to commit the selected value immediately is ticked, under the Options tab of the Properties dialogs of your drop-down fields.

 

If you're interested, I've developed a (paid-for) tool that allows you to set up such "cascading" drop-downs very easily and quickly, without having to write any code. All you need is to have a spreadsheet with all the possible combinations and then you run the script on it and it sets it all up for you. You can find it here: http://try67.blogspot.com/2014/11/acrobat-create-cascading-dropdowns.html

I can also help you set up the last step you described, populating a text field based on the last value selected.

pbmzbr
pbmzbrAuthor
Participating Frequently
June 21, 2020

Hello, try67.

 

Thank you for your notes.

 

Answering your points:

- Yes. The correct is "setItems". My mistake.

- From what I researched, I thought I used an Array. OK. I will search better.

- In this case, don't I need to use the keystroke?

- It is.

 

Thank you for the offer, but what I'm doing is nonprofit. So I appreciate it, but I don't want to pay for the help.

Thank you very much for your notes. They were enlightening. I will put them into practice immediately. 🙂

 

try67
Community Expert
Community Expert
June 21, 2020

Hello, again.

 

- I am using an Array.

var e = ["Especialização", "Ranger", "Bardo", "Assassino"];

 

- I changed from Format to Validate, but now it doesn't create the Dropdown list.


- In this line you're not:

else e = '';

- Again, check the JS Console for errors.