@yisrael-wix Hi Yisrael,
Thanks for your help.
So I’ve added in your Remove Dropdown Duplicates code on the second dropdown. And it works!
However, it’s not connected with the first drop down selection and it doesn’t display what’s selected in second dropdown.
Im just missing how to connect that Remove Dropdown Duplicates code with my first dropdown selection. I think it may need to be triggered on change of the dropdown and not on page load. I’m just not sure.
Would you have two minutes to look at it for me? I’d so appreciate it. It’s the last thing left to sort on the website before we go live with it! (and Premium)
I really appreciate your help.
I’ve learnt a load so far. Thanks so much.
https://vanpower.wixsite.com/aeairl/meetings
Vanessa
See code below. I just need to know how to connect the Duplicates Code with my second dropdown. There’s code for that below that was working but producing the duplicates.
import wixData from ‘wix-data’;
$w.onReady( function (){
// Run a query that returns all the items in the collection
wixData.query(“Meetings”)
// 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(“#dropdown2”).options = buildOptions(uniqueTitles);
console.log(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.newField);
// 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};
});
}
});
// First dropdown code. Listing the Countries
export function dropdown1_change(event, $w) {
$w(“#dropdown2”).enable();
locationCountryFilter();
//uniqueDropDown1();
}
function locationCountryFilter (){
$w(“#dataset1”).setFilter( wixData.filter()
.eq(“title”, $w(“#dropdown1”).value)
);
}
// Second dropdown code. Listing the Cities
//This is what I had in for the second dropdown that was working but was producing the duplicates. So how do I connect your duplicates code to this? I have it commented out while I was adding your Duplicate Code. Help here so appreciated! Thanks.
/*export function dropdown2_change(event, $w) {
$w(“#dropdown2”).enable();
locationCityFilter();
}
function locationCityFilter (){
$w(“#dataset1”).setFilter( wixData.filter()
.eq(“newField”, $w(“#dropdown2”).value)
);
}
*/
THANK YOU!!