Expand my Community achievements bar.

SOLVED

addItems to Dropdown avoiding duplicates

Avatar

Level 3

Sir.

Link to the actual file  https://www.dropbox.com/s/0508by0lmlf77rc/repeatable%20Dropdown%20to%20another%20Dropdown%20which%20...

 

I have 2 dropdowns     

1st is in a repeating table  and 2nd one is in a repeatable subform

1st dropdown has options  say  Option1, Option2 ...... 

2nd Dropdown is empty when intialized

 

I want when user selects any option in dropdown 1  it should be populated in dropdown2  avoiding duplicates

so if user adds say 3 rows  and select in

1st Row : Option1

2nd Row : Option2

3rd row : Option3

 

then Dropdown2 should have the following options for the user to select from

Option1

Option2

Option3

if user goes back and deletes any row then that option should be removed from Dropdown2    and  duplicate items should be avoided. 

 

Thanks 

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 10

This needs a combination of two loops. One to fetch the selected value and one to compare those already used.

 

 form1.MSF.SF_Notable.SF1.RB::enter - (JavaScript, client)

var oRows = Table1.resolveNodes('Row2.[Cell1 ne "  -Select-"]'),
	oNode, oItems, i, j, n, cValue;
this.clearItems();
for (i = 0; i < oRows.length; i += 1) {
	oNode = oRows.item(i);
	oItems = this.items.resolveNodes('#text[*]');
	n = 0;

	if (oNode.Cell1.rawValue === "  Example Other Member" ) {
		cValue = oNode.Cell2.rawValue;
	} else {
		cValue = oNode.Cell1.rawValue;
	}
		
	for (j = 0; j < oItems.length; j += 1) {
		if (cValue == oItems.item(j).value) {
			n += 1;
		}
	}

	if (n === 0) {
	    this.addItem(cValue);
	}
}

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

This needs a combination of two loops. One to fetch the selected value and one to compare those already used.

 

 form1.MSF.SF_Notable.SF1.RB::enter - (JavaScript, client)

var oRows = Table1.resolveNodes('Row2.[Cell1 ne "  -Select-"]'),
	oNode, oItems, i, j, n, cValue;
this.clearItems();
for (i = 0; i < oRows.length; i += 1) {
	oNode = oRows.item(i);
	oItems = this.items.resolveNodes('#text[*]');
	n = 0;

	if (oNode.Cell1.rawValue === "  Example Other Member" ) {
		cValue = oNode.Cell2.rawValue;
	} else {
		cValue = oNode.Cell1.rawValue;
	}
		
	for (j = 0; j < oItems.length; j += 1) {
		if (cValue == oItems.item(j).value) {
			n += 1;
		}
	}

	if (n === 0) {
	    this.addItem(cValue);
	}
}

Avatar

Administrator

Good to see you in AEM community. Nice you have great SME like you.  



Kautuk Sahni