Need Help to Filter Duplicates from drop down menu

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

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

Take a look at the forum post 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

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!

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

Hey Darnell,

Take a look at the Cascading Form example. It does just what you want.

Good luck,

Yisrael

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.

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!!

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”:


You can also connect the list using code. Use whichever way is best for you.

Yisrael

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.

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 discuss just such an issue.