Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.

Please help with detecting duplicates in listbox

Avatar

Level 3

Hi guys,

I have a question concerning the code that I am using for  2 listboxes.

I have 1. Listbox=SOLWindow.Description which contains values imported from XML. If I select values from this listbox, they should appear in the 2.listbox = SOLlist. This works fine, but what I am trying to do now is when I click in the 1.listbox on the value that I have already selected and populated in the 2. listbox, an error message should appear app.alert("You have already selected this item!"), but I dont even get the values compared with my code.

I would appreciate if anyone could help to find out what is wrong with my code!!

if

(PAGE2.SOLWindow.Description.selectedIndex>=0)

{

newitem

= "";

olditem

= PAGE2.SOLWindow.Description.rawValue;

if(newitem != olditem)

{

SOLlist.addItem(PAGE2.SOLWindow.Description.rawValue);

newitem

= PAGE2.SOLWindow.Description.rawValue;

}

else

{

app.alert("true");

}

}

Thank you in advance!!

Diana

2 Replies

Avatar

Level 6

If I understood your request correctly....

you are trying to add the selected item in DD1 to DD2 and if that is been already selected you want to display "Already Selected" and do not add it second time in the list.....

Following code segment should help you do that.....use this code in DD1's "change" event

//check for value of associated item with this text in SOLlist Dropdown

//it return null if there is no item found
//it return value associated with text if item exists

if (SOLlist.boundItem(xfa.event.newText) == "") { 

  SOLlist.addItem(xfa.event.newText);
}
else {
xfa.host.messageBox("Exists");
}

Note: may have to tune based on you Hierarchy.

Good luck,

Avatar

Level 3

Thank you so much!!

I could use  your code, I just had to replace the xfa.event.newText.

But now it works perfectly!!!

Thanks again!!!!!!!!!!!!!!!!!!!!!

Diana