# Dropdown Duplicates

**URL:** <https://forum.wixstudio.com/t/dropdown-duplicates/40105>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [April 9, 2018, 7:33am UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105 "2018-04-09T07:33:53Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![anseric-soete](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anseric-soete/32/2946_2.png) [@anseric-soete](https://forum.wixstudio.com/u/anseric-soete)\
**Post date:** [April 9, 2018, 7:33am UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/1 "2018-04-09T07:33:53Z")

</div>

Hello

I’ve tested multiple tutorials but none seem to work.  
I have a dropdown via “Connect a list” and have many duplicates.

Here you can see my code.

```javascript
import wixData from 'wix-data';
export function iRegion_change(event, $w) {
 wixData.query('Jobs') 
  // Query the collection for any items whose "Name" field contains  
  // the value the user selected in the dropdown
  .contains('regio', $w('#iRegion').value)
  .find() // Run the query
  .then(res => {   
     // Set the table data to be the results of the query
     $w('#table1').rows = res.items; 
   }); 
}

$w.onReady(function () {
	// Run a query that returns all the items in the collection
	wixData.query("Jobs")
		// Get the max possible results from the query
		.limit(1000)       
  		.find()
  		.then(results => {
  			// Call the function that creates a list of unique titles
		  	const uniqueTitles = getUniqueTitles(results.items);   
			// Call the function that builds the options list from the unique titles
		  	$w("#iRegion").options = buildOptions(uniqueTitles);    
  		});
	// Builds an array from the "Title" field only from each item in 
	// the collection and then removes the duplicates
  	function getUniqueTitles(items) {    
  		// Use the map method to create the titlesOnly object containing all the titles from the query results
    		const titlesOnly = items.map(item => item.title);   
		// Return an array with a list of unique titles
       		return [...new Set(titlesOnly)];
	}
	// Creates an array of objects in the form {label: "label", value: "value"} from the array of titles
	function buildOptions(uniqueList) {   
		return uniqueList.map(curr => {
			// Use the map method to build the options list in the format {label:uniqueTitle, value:uniqueTitle}
			return {label:curr, value:curr};  
		});
	}
});

```

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [April 9, 2018, 8:01am UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/2 "2018-04-09T08:01:18Z")

</div>

Hi Anseric,

Welcome to the Wix Code forums.

Take a look at the forum post [Remove duplicates from connected dropdown options](https://www.wix.com/code/home/forum/advanced-tips-tricks/remove-duplicates-from-connected-dropdown-options) . You’re not the first to ask about this ☺

Good luck,

Yisrael

---

<div class="post-metadata">

**Author:** ![anseric-soete](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anseric-soete/32/2946_2.png) [@anseric-soete](https://forum.wixstudio.com/u/anseric-soete)\
**Post date:** [April 9, 2018, 8:48am UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/3 "2018-04-09T08:48:02Z")

</div>

Hello

Sadly enough I tried his method but it doesn’t seem to work.  
I’ve read the comments but no solution at first sight. I’m missing something on how to create my dropdown I guess but can’t seem to figure it out.

Thanks anyway!

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [April 9, 2018, 8:55am UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/4 "2018-04-09T08:55:15Z")

</div>

Make sure that you disconnect the dropdown list items from the collection:

![](https://us1.discourse-cdn.com/wix/original/3X/7/5/756903cbef67f7639fce4dd17684b713d74687f0.png)  
I hope this helps. If not, please post the URL of your site. _Only authorized Wix personnel can get access to your site in the editor._

---

<div class="post-metadata">

**Author:** ![anseric-soete](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anseric-soete/32/2946_2.png) [@anseric-soete](https://forum.wixstudio.com/u/anseric-soete)\
**Post date:** [April 9, 2018, 11:19am UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/5 "2018-04-09T11:19:49Z")

</div>

Hello

I’ve tried that but it doesn’t seem to work.  
If i disconnect another list is used.

---

<div class="post-metadata">

**Author:** ![anseric-soete](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anseric-soete/32/2946_2.png) [@anseric-soete](https://forum.wixstudio.com/u/anseric-soete)\
**Post date:** [April 10, 2018, 7:07am UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/6 "2018-04-10T07:07:35Z")

</div>

Hello

Is it possible to take a look? I want the dropdown to show regions but no duplicates.  
And if possible an “All Regions” option.

[https://www.digitalents.be/test-search](https://www.digitalents.be/test-search)

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [April 10, 2018, 8:40am UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/7 "2018-04-10T08:40:51Z")

</div>

Hi Anseric,

I tried this out and the dropdown list looks just fine - no duplicates.

To get the correct field, change your function to use **item.regio** :

```javascript
function getUniqueregio(items) {    
    // Use the map method to create the titlesOnly object containing all the titles from the query results
    const regioOnly = items.map(item => item.regio); // changed
    // Return an array with a list of unique titles
    return [...new Set(regioOnly)];
}

```

There is a duplicate in the dropdown list:

 ![](https://us1.discourse-cdn.com/wix/original/3X/e/b/eb3b0f98fb3d446cb32ef7db95627c850d8e1504.png)  
The reason for that is that one of the items in the database has a space added to the end of the region name, which makes it different than the others:

![](https://us1.discourse-cdn.com/wix/original/3X/1/a/1ad0e9e3232f02f3361d5e8c93fc931a5c346ec1.png)  
Notice the space before the cursor.

I hope this helps. Let me know how it goes.

Yisrael

---

<div class="post-metadata">

**Author:** ![anseric-soete](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anseric-soete/32/2946_2.png) [@anseric-soete](https://forum.wixstudio.com/u/anseric-soete)\
**Post date:** [April 10, 2018, 2:30pm UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/8 "2018-04-10T14:30:35Z")

</div>

Thanks Yisrael

I’ve been to close to see such a stupid mistake, thanks for the help!

---

<div class="post-metadata">

**Author:** ![anseric-soete](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/anseric-soete/32/2946_2.png) [@anseric-soete](https://forum.wixstudio.com/u/anseric-soete)\
**Post date:** [April 10, 2018, 2:37pm UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/9 "2018-04-10T14:37:09Z")

</div>

Final Question.  
I tried with the “All Continents” code but can’t get “All Region”

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [April 10, 2018, 5:35pm UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/10 "2018-04-10T17:35:09Z")

</div>

Hey Anseric,

Change this code:

```javascript
// Call the function that creates a list of unique titles
const uniqueTitles = getUniqueTitles(results.items);   
// Call the function that builds the options list from the unique titles
$w("#iRegion").options = buildOptions(uniqueTitles);

```

To this:

```javascript
// Call the function that creates a list of unique titles 
const uniqueTitles = getUniqueTitles(results.items);   
// Call the function that builds the options list from the unique titles            
let newList = buildOptions(uniqueTitles);
newList.unshift({ // add "All Regions" to beginning of array
   "value": '',
   "label": 'All Regions' 
});
$w("#iRegion").options = newList; // set the dropdown list

```

Have fun,

Yisrael

---

<div class="post-metadata">

**Author:** ![therobertrees](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/therobertrees/32/4162_2.png) [@therobertrees](https://forum.wixstudio.com/u/therobertrees)\
**Post date:** [May 24, 2018, 11:29pm UTC](https://forum.wixstudio.com/t/dropdown-duplicates/40105/11 "2018-05-24T23:29:51Z")

</div>

Yisreal, the problem I have is when you say in the 4th post down, “Make sure that you disconnect the dropdown list items from the collection:”

Once I do that how do I get my drop down to go to the correct Dynamic Page?

Dropdown no longer has duplicates, but now it doesn’t go anywhere when I select an item. Whereas before coding it, the item would take me to the correct Dynamic Page, but there were 20 of each item listed in the dropdown!

## I’ve tried wix-location.to & that isn’t working. been at this for days

import wixData from ‘wix-data’;  
import wixLocation from ‘wix-location’;

$w.onReady(function () {  
// Run a query that returns all the items in the collection  
wixData.query(“PartsList”)  
// Get the max possible results from the query  
.limit(1000)  
.ascending(“title”)  
.find()  
.then(results =\> {  
// Call the function that creates a list of unique titles  
const uniquetitles = getUniquetitles(results.items);  
// Call the function that builds the options list from the unique titles  
$w(“#iManufacturer”).options = buildOptions(uniquetitles);  
});  
$w(“#iManufacturer”).placeholder = “Products by Manufacturer”;  
// Builds an array from the “title” field only from each item in  
// the collection and then removes the duplicates  
function getUniquetitles(items) {  
// Use the map method to create the titlesOnly object containing all the titles from the query results  
const titlesOnly = items.map(item =\> item.title);  
// Return an array with a list of unique titles  
return […new Set(titlesOnly)];  
}  
// Creates an array of objects in the form {label: “label”, value: “value”} from the array of titles  
function buildOptions(uniqueList) {  
return uniqueList.map(curr =\> {  
// Use the map method to build the options list in the format {label:uniquetitle, value:uniquetitle}  
return {label:curr, value:curr};  
});  
}  
});  
export function iManufacturer\_change(event, $w) {  
$w(“#dataset1”).setCurrentItemIndex(event.target.selectedIndex)  
.then( () =\> {  
wixLocation.to($w(“#dataset1”).getCurrentItem().title);  
} );  
}
