# Need Help to Filter Duplicates from drop down menu

**URL:** <https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [April 23, 2018, 11:00pm UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641 "2018-04-23T23:00:04Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![darnell-burt](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@darnell-burt](https://forum.wixstudio.com/u/darnell-burt)\
**Post date:** [April 23, 2018, 11:00pm UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/1 "2018-04-23T23:00:04Z")

</div>

Reviewed several threads and tried to customize and use suggested code but seem to be stuck and can use some help… I have setup the following:

1. Database - TournamentRegistration
2. Drop down neme - xboxdropdown
3. Field in Tournament Database called xboxgamertag

I had it connected to the database via connect to options of the dropdown. It works but the flaw is that if you have more than one entry of the same name in the database the dropdown would show duplicates. So I attempted to apply code to remove duplicates. I reviewed several post in which people where having the same problem and used some of the code that helped them. The current code I have gives me no errors in code page but when I try to use the dropdown it doesn’t show any items or really doesn’t do anything. If anyone can help it would be much appreciated… A fresh pair of eyes would be great! Here is the code below.

import wixData from ‘wix-data’;

$w.onReady(function () {  
wixData.query(“TournamentRegistration”)  
.limit(1000)  
.find()  
.then(results =\> {  
const uniquexboxgamertag = getUniquexboxgamertag(results.items);  
$w(“#xboxdropdown”).options = buildOptions(uniquexboxgamertag);  
});  
function getUniquexboxgamertag(items) {  
const xboxgamertagOnly = items.map(item =\> item.title);  
return […new Set(xboxgamertagOnly)];  
}  
function buildOptions(uniqueList) {  
return uniqueList.map (curr =\> {  
return {label:curr, value:curr};  
});  
}  
});

---

<div class="post-metadata">

**Author:** ![braden432](https://avatars.discourse-cdn.com/v4/letter/b/5e9695/32.png) [@braden432](https://forum.wixstudio.com/u/braden432)\
**Post date:** [April 24, 2018, 1:33am UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/2 "2018-04-24T01:33:48Z")

</div>

Have you tried using console.log(uniquexboxgamertag); after  
const uniquexboxgamertag = getUniquexboxgamertag(results.items);  
to see if you’re getting the values in the first place?

Are you viewing on the mobile device or a desktop device? (I’m having a similar issue on the mobile platform)  
How many records in you TournamentRegistration database? (it will only read in the first 1,000)  
Have you made sure that the xboxgamertag db field value is “title”? go to the field in the db, click the three dots next to the field name, click manage properties and look as the “Field key” that is what you use in item.xxxx  
const xboxgamertagOnly = items.map(item =\> item. **title** );

Good luck

---

<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 24, 2018, 6:56am UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/3 "2018-04-24T06:56:46Z")

</div>

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) . I’ve used this mechanism myself and it works great. Also, read the comments on that post for further hints and techniques possible.

Good luck,

Yisrael

---

<div class="post-metadata">

**Author:** ![darnell-burt](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@darnell-burt](https://forum.wixstudio.com/u/darnell-burt)\
**Post date:** [April 24, 2018, 11:35am UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/4 "2018-04-24T11:35:11Z")

</div>

Thank You both for your responses. And especially thank you Braden432 that was the exact problem the field key was set incorrectly. I really appreciate the response. Read your bio. We have similar backgrounds! If interested I have several projects you can be involved in! Just let me know and we can figure something out!

---

<div class="post-metadata">

**Author:** ![darnell-burt](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@darnell-burt](https://forum.wixstudio.com/u/darnell-burt)\
**Post date:** [April 24, 2018, 6:15pm UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/5 "2018-04-24T18:15:55Z")

</div>

Filter is working great, the code filters out the duplicates but I noticed it shows all items in the database. What approach could I take to have code continue filtering duplicates but only show items from a specified group.

For example Users login and are directed to a form. Form contains input field from user which is a registration number dropdown. Then form has a second dropdown which shows the field (xboxgamertag) for all entries in database (code above filters out duplicates). Question would be what can I add to current code to allow second dropdown to only show field (xboxgamertag) that are associated with the registration dropdown. Thanks for your help

---

<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 25, 2018, 9:12am UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/6 "2018-04-25T09:12:59Z")

</div>

Hey Darnell,

Take a look at the [Cascading Form](https://www.wix.com/code/home/example/Cascading-Form) example. It does just what you want.

Good luck,

Yisrael

---

<div class="post-metadata">

**Author:** ![darnell-burt](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@darnell-burt](https://forum.wixstudio.com/u/darnell-burt)\
**Post date:** [April 25, 2018, 3:29pm UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/7 "2018-04-25T15:29:08Z")

</div>

Yisrael,

I have already looked at that example. And unfortunately that example differs from what Im asking. In the example your referring to the items (States, Country) are predetermined and typed out in the public .js then imported into script for use. I need script that is able to gather information from database which was obtained from forms. Their is no predetermined data.

---

<div class="post-metadata">

**Author:** ![darnell-burt](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@darnell-burt](https://forum.wixstudio.com/u/darnell-burt)\
**Post date:** [April 25, 2018, 7:32pm UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/8 "2018-04-25T19:32:51Z")

</div>

Yisrael,  
I have went through practically all of the forum related to similar issues and couldn’t find a solution. Although it gave me a wealth of knowledge which allowed me to solve some other problems. But any suggestions that might lead me down the right path!!

---

<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 26, 2018, 6:41am UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/9 "2018-04-26T06:41:17Z")

</div>

What you need is to connect the dropdown to a filtered dataset that provides the list of items. Not much different than using a static predetermined list. It’s just a matter of connecting to a dataset, and setting the filter for the dataset.

Here is how to connect from the “Connect Dropdown Panel”:

 ![](https://us1.discourse-cdn.com/wix/original/3X/d/3/d3dc5fcb79beefcd7e4e3765bfa35bcde3632e55.png)  
You can also connect the list using code. Use whichever way is best for you.

Yisrael

---

<div class="post-metadata">

**Author:** ![darnell-burt](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@darnell-burt](https://forum.wixstudio.com/u/darnell-burt)\
**Post date:** [April 26, 2018, 8:02pm UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/10 "2018-04-26T20:02:41Z")

</div>

Yisrael,

Remember The above code filters duplicates. In order for code to work you have to disconnect dropdown from the connect options. What I am asking has to be added via code.

---

<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 29, 2018, 5:43am UTC](https://forum.wixstudio.com/t/need-help-to-filter-duplicates-from-drop-down-menu/37641/11 "2018-04-29T05:43:15Z")

</div>

If you want to use the filter-duplicates code for the second dropdown as well, then just connect via code as you did for the first dropdown. The comments on 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) discuss just such an issue.
