Help needing for using search filters

I’m just getting started with Corvid and have a limited understanding of Javascript and programming in general.

I followed the video along relatively well ( https://www.youtube.com/watch?v=mTRSPNosLRw&t=256s ) and was able to get the search functionality working fine.

However, no matter how hard I try, I cannot get the dropdown filter to load the values from my dataset.

I’ve gone as far as copy-pasting the code from the sample and simply changing the values, but cannot get it to work.

Any ideas on what else I could look at?


Here’s my code. The only difference is instead of “Continents” I have “Categories” and “Artists”. I’ve tried with each by itself as well, but that hasn’t helped.

import wixData from “wix-data”;

$w.onReady( ()=> {
loadCategories();
loadArtists()
});

let lastFilterTitle;
let lastFilterCategory;
let lastFilterArtist;
let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iTitle’).value, lastFilterCategory);
}, 500);
}

export function iCategory_change(event, $w) {
filter(lastFilterTitle, $w(‘#iCategory’).value);
}

export function iArtist_change(event, $w) {
filter(lastFilterTitle, $w(‘#iArtist’).value);

}

function filter(title, category, artist) {
if (lastFilterTitle !== title || lastFilterCategory !== category || lastFilterArtist !== artist) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘videoTitle’, title);
if (category)
newFilter = newFilter.contains(‘category’, category);
if (artist)
newFilter = newFilter.contains(‘artist’, artist);
$w(‘#dataset1’).setFilter(newFilter);
lastFilterTitle = title;
lastFilterCategory = category;
lastFilterArtist = artist;
}
}

function loadCategories() {
wixData.query(‘Category’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”: ‘All Categories’}];
options.push(…res.items.map(category => {
return {“value”: category.title, “label”: category.title};
}));
$w(‘#iCategory’).options = options;
});

}

function loadArtists() {
wixData.query(‘Artist’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”:‘All Artists’}];
options.push(…res.items.map(artist => {
return {“value”: artist.title, “label”: artist.title};
}));
$w(‘#iArtist’).options = options;
});
}

If you are using the code from this tutorial which is already all setup in an Wix editor example:
https://www.wix.com/corvid/tutorial/How-to-Create-a-Search-for-Your-Database

Then please make sure that all your code is correct and there are no missing () or {} for example. Plus, also make sure that all the names of your elements and dataset field keys, simply changing one field key from category to Category can break your code.

Also, make sure that you have activated any events in the properties panels for any events that need it, like the title, artist and category export functions of the code. Otherwise you will have to write it into your code inself so that you don’t need to add it through the properties panel.

Finally have a look at the dropdown tutorial youtube video from Nayeli (Code Queen):
https://www.youtube.com/watch?v=Lhq8X7m0Xic

Also, have a read of these previous posts:
https://www.wix.com/corvid/forum/wix-tips-and-updates/how-to-create-a-search-for-your-database
https://www.wix.com/corvid/forum/community-discussion/need-help-filtering-a-dataset-with-a-dropdown-adding-search
https://support.wix.com/en/article/about-filtering-and-sorting-database-content-displayed-in-page-elements