Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Dynamically add values to a dropdown within a table

Avatar

Former Community Member

Hi All,

    Could you please help me with the following question.

I have a dynamic table and in one of the columns of the table I have a drop down. For simplicity lets say I have added the values x, y, z in the drop down.

I then click an Add button to add a row in the table. The drop down in the next row has the same values x,y,z.

What I want to do is add values in the drop down dynamically and then have these values available in the drop down when I add another row to the

table.

What is happening at the moment is that the values get added to the drop down in the first row ... but when I then add a row to the table these dynamically

added values are no longer available.

Thanks,

Jayant

1 Reply

Avatar

Level 10

Hi Jayant,

Maybe you can have all the subsequent dropdownlist controls copy the items from the first one,  so add this JavaScript in the preOpen event of the dropdownlist.


function cloneItems(sourceDropDown, targetDropDown)
{
var values = [];
var ids = [];
var items = sourceDropDown.resolveNodes("#items.#text[*]");

for (var i = 0; i < items.length; i++)
{
  var dropDownValue = items.item(i).value;
  values.push(dropDownValue);
  ids.push(sourceDropDown.boundItem(dropDownValue));
}

targetDropDown.clearItems();
for (var i = 0; i < values.length; i++)
{
  targetDropDown.addItem(values[i], ids[i]);
}
}


if (Row1.index > 0)
{
cloneItems(Table1.Row1.DropDownList1, this)
}


Just change line 22 (the call to cloneItems, to reference the dropdown in your form)

Regards

Bruce