Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

addItems to Dropdown avoiding duplicates

rakeshk21205956
Level 3
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
radzmar
Correct answer by
Level 10
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
radzmar
Correct answer by
Level 10
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

kautuk_sahni
Community Manager
Community Manager

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