addItems to Dropdown avoiding duplicates | Community
Skip to main content
rakeshk21205956
Level 3
August 23, 2021
Solved

addItems to Dropdown avoiding duplicates

  • August 23, 2021
  • 1 reply
  • 1189 views

Sir.

Link to the actual file  https://www.dropbox.com/s/0508by0lmlf77rc/repeatable%20Dropdown%20to%20another%20Dropdown%20which%20is%20also%20repeatable..pdf?dl=0

 

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 

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by radzmar

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);
	}
}

1 reply

radzmar
radzmarAccepted solution
Level 10
August 26, 2021

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);
	}
}
rakeshk21205956
Level 3
August 28, 2021

@radzmar Thanks again

This works perfect.