Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Help me with populating a drop down field depending another drop down field

Avatar

Level 2

Goog afternoon everybody, help me with this please.

I have three drop-down lists, and each drop-down list depends on another drop-down list, when I click the second drop-down list, and then click the first drop-down list, the content of the first drop-down list is repeated each time I click the second drop-down list. Please help to resolve this situation, perhaps i may send the pdf form to somebody.

Sincerely

orlando

first_clic.jpg

content_first_clic.jpg

second_clic.jpg

content_second_clic.jpg

third_clic.jpg

content_third_clic.jpg

and so on ...

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Sounds like you need a {DropDownList1}.clearItems(); somewhere in your code before you start adding the new items.

If that doesn't help then add your code to the thread, or maybe a link to your form.

Regards

Bruce

View solution in original post

9 Replies

Avatar

Correct answer by
Level 10

Hi,

Sounds like you need a {DropDownList1}.clearItems(); somewhere in your code before you start adding the new items.

If that doesn't help then add your code to the thread, or maybe a link to your form.

Regards

Bruce

Avatar

Level 2

Hi Bruce, thanks for answering,

The link for the file is https://mega.nz/#!qDYQAKoY!jj7s-yK8VePAkZX5_AsXB7KYXrP-dZh6sMIQbqFQIxA

this is the enter event code for the first drop-down:

if (this.rawValue == null)

{var arrayItems = eval(Secretarias.value);for (var i=0; i < arrayItems.length; i++)

{this.addItem(arrayItems[i]);}}

and this code for the change event:

Direcciones_.rawValue = null;Direcciones_.clearItems();Direcciones_.setItemState(0, true);

Unidades_.rawValue = null;Unidades_.clearItems();Unidades_.setItemState(0, true);

this is the enter event code for the second drop-down:

if (Secretarias_.rawValue == "SECRETARIA MUNICIPAL DE PLANIFICACION Y DESARROLLO TERRITORIAL" && this.rawValue == null)

    {var arrayItems = eval(Direccion_1.value);for (var i=0; i < arrayItems.length; i++)

    {this.addItem(arrayItems[i]);this.setItemState(0,1);}}

if (Secretarias_.rawValue == "SECRETARIA MUNICIPAL DE FINANZAS Y ADMINISTRACION" && this.rawValue == null)

    {var arrayItems = eval(Direccion_2.value);for (var i=0; i < arrayItems.length; i++)

    {this.addItem(arrayItems[i]);this.setItemState(0,1);}}

and this code for the change event:

Unidades_.rawValue = null;Unidades.clearItems();Unidades_.setItemState(0, true);

for the third drop-down the code for the enter event is:

if (Direcciones_.rawValue == "DIRECCION DE GESTION URBANA Y TERRITORIAL" && this.rawValue == null)

{var arrayItems = eval(Unidad_1.value);for (var i=0; i < arrayItems.length; i++)

{this.addItem(arrayItems[i]);this.setItemState(0,1);}}

if (Direcciones_.rawValue == "DIRECCION DE INGRESOS Y SERVICIOS MUNICIPALES" && this.rawValue == null)

{var arrayItems = eval(Unidad_2.value);for (var i=0; i < arrayItems.length; i++)

{this.addItem(arrayItems[i]);this.setItemState(0,1);}}

Also in the Form Properties made five variables:

Secretarias.png

Direccion_1.png

Direccion_2.png

Unidad_1.png

Unidad_2.png

Thanks for your help

Avatar

Level 10

Hi,

Your file is password protected, so I haven't had a look.  But I would look at moving the code to populate the drop down item list into the preOpen event of the drop down, which is what it is for.  I would guess the enter event is being called more often than you expect.

Also, from Reader 9.0 there is a setItems() method, so as long as your form fillers aren't using a rather old version then you can set all the items in one hit, like;

Currency.setItems("US Dollar,USD,Canadian Dollar,CAD,Euro,EUR,United Kingdom Pounds,GBP", 2)

If you still want me to have a look can you take the password off.

Bruce

Avatar

Level 2

Hi Bruce, I'm sorry I forgot to remove the password, this is de pdf form without password

https://mega.nz/#!KWonjQqB!_VzmNLCIfVMbnMyilQY-oBYlryd1My_SnhS1LtL7K2A

Thanks for your help

Avatar

Level 10

Have a look at this sample;

https://sites.google.com/site/livecycledesignercookbooks/home/Catastro_unprotected_updated.pdf?attre...

I've moved the code to the preOpen and used the setItems method, if you don't need the values from the form variables in an array for something else, then you might want to change them to a csv format and then you could remove the call the the eval() function

Avatar

Level 2

Hi Bruce, thanks so much for helping me, by the option you say, can you please tell me how to change to a csv format and modify the form

Avatar

Level 2

Bruce, by the way, now the pdf form works perfectly, thanks a lot.

Avatar

Level 10

Hi,

I meant that if you changed the form variable to the format like;

,SECRETARIA MUNICIPAL DE PLANIFICACION Y DESARROLLO TERRITORIAL,SECRETARIA MUNICIPAL DE FINANZAS Y ADMINISTRACION

That is a CSV list, then code would only need to be

this.setItems(Secretarias.value);

Just, seemed a bit neater

Bruce