I followed the tutorial provided by wix in regard to creating a search bar & dropdown, and the search bar works fine but for the dropdown button does respond to anything when i choose an option the page just becomes blank & the all categories option doesn’t even show! i’m not sure what’s wrong?? There’s no errors in the codes it just doesn’t work on the dropdown please help me I’ve been struggling with this problem for 2 days now and the deadline is soon!!
below are my codes!!
import wixData from "wix-data";
$w.onReady(() => {
wixData.query('projectType')
.find()
.then(res => {
let options = [{"value": '', "label": 'All Project Types'}];
options.push(...res.items.map(project => {
return {"value": project.title, "label": project.title};
}));
$w('#dropdown1').options = options;
});
});
let lastFilterTitle;
let lastFilterProject;
let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iTitle').value, lastFilterProject);
}, 500);
}
function filter(title, project) {
if (lastFilterTitle !== title || lastFilterProject !== project) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains('groupName', title);
if (project)
newFilter = newFilter.contains('projectType', project);
$w('#dataset1').setFilter(newFilter);
lastFilterTitle = title;
lastFilterProject = project;
}
}
export function dropdown1_change(event, $w) {
filter(lastFilterTitle, $w('#dropdown1').value);
}
Hi,
Just looked into your code and i see a few issues:
You dont have a dataSet named projectType. meaning that the code you use to fill in the dropdown never runs.
now, you manually entered the dropdown entries. the value you entered for “Fan Art” is “fanart” and when you filter data by that, nothing shows because in the artist collection it says “Fan Art”.
Thanks so much for the response! The dropdown now works, but the All Project Types option still doesn’t appear and if I add it manually to the dropdown list it is not responsive. Is there any way to fix that?
That was actually what I tried to do but they didn’t let me leave a blank value?
That’s why I ended up trying with the quotation marks inside! Is there any way to leave it blank?
I seem to be following the instructions pretty badly I’m so sorry this seems like a pretty trivial thing but I’m not figuring it out correctly…
You’re right, another solution is you can enter any other value here and than exclude it in your filtering code. for example, put “Any” as a value and than add this to your if() statement inside the filter function