Expand my Community achievements bar.

How to add values to a dropdown upon initialize

Avatar

Level 2

I am creating a dropdown list - where users can choose the proper year of business.

This dropdown needs to be customized to the user:

  • Values begin at the year the business began to generate hazardous waste
  • I need to add values for each year - up to the current year.

I want the current year to be calculated instead of static.

How do I add values to a dropdown list?

In LiveCycle - I would do something like this:

    

for (var i=dateBaseYear.rawValue; i<=dateCurrentYear.rawValue; i++)

{

//console.println(i);

this.addItem("" + i); //needed to add a string in front of 'i'.  not sure why

}

Is there a similar solution for AEM Forms?

6 Replies

Avatar

Employee Advisor

Hi John,

I guess you are working with adaptive forms, you should use rule editor to set the values in drop-down list. Please refer Adobe Experience Manager Help | Adaptive forms rule editor.

Thanks,

Mayank

Avatar

Level 2

I have saved the Guide and refer to it constantly.

Is there an example that I can reference?  I cannot seem to find out to add each value - via the rule editor.

Thanks

Avatar

Employee Advisor

I will create some sample script and share with you shortly.

Avatar

Level 2

Mayank,

Any progress?  Looking forward to seeing an example.

Thanks

John

Avatar

Employee Advisor

Hi John,

Somehow I missed this thread, did you got this sorted out already?

Avatar

Level 7

The DropDownList can be programmatically populated in the initialise event using an array of key=value pairs [1] on the items property [2]. So for your particular example, to populate the list starting at the current year and running for 5 years would look something like:

(on the initialise event)

var currentYear = (new Date()).getFullYear();

this.items = [];

for (var i = 0 ; i < 5 ; i++) {

  this.items.push(i + "=" + currentYear-- + " Item Name");

}

The above code will add 5 entries to the drop down list

0=2018 Item Name

1=2017 Item Name

...

4=2014 Item Name

When the item is selected, the key will be stored in the field property. If you want the value stored instead, then just leave out the key= part to the item string when you are adding it to the items array.

[1] Adobe Experience Manager Help | Adaptive Form Expressions

[2] Adaptive Forms Class: GuideDropDownList