For testing purposes, I’ve created a data collection with 6 records. I have a search box and a dropdown menu for filtering. I need to add to the dropdown menu, a choice that reads “Select Subject,” which will reset the dropdown list to its original state (i.e., as if a filter has not been performed yet.) What code do I need to reset a dropdown list? I haven’t been able to find any (code) on the forum to accomplish what I’m trying to achieve. Any help would be greatly appreciated. Following is what I’ve written thus far. I’m also getting an error message that reads, "iCategory is not a valid selector on my last line - $w( ‘iCategory’ ).options = options.
import wixData from "wix-data";
$w.onReady(() => {
loadACFreelancers();
});
let lastFilterExpertise;
let lastFilterCategory;
let debounceTimer;
export function iExpertise_keyPress(event) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iExpertise').value, lastFilterCategory);
}, 500);
}
export function iCategory_click_1(event) {
filter(lastFilterExpertise, $w('#iCategory').value);
}
function filter(expertise, category) {
if (lastFilterExpertise !== expertise || lastFilterCategory !== category) {
let newFilter = wixData.filter();
if (expertise)
newFilter = newFilter.contains('expertise', expertise);
if (category)
newFilter = newFilter.contains('category', category);
const filterValue = $w("#iCategory").value
const byAssignment = wixData.filter().contains("assignment", filterValue)
const byHumanities = wixData.filter().contains("humanities", filterValue)
const bySocialSciences = wixData.filter().contains("socialSciences", filterValue)
const byTopics = wixData.filter().contains("topics", filterValue)
const byOther = wixData.filter().contains("other", filterValue)
$w("#dataset1").setFilter(byAssignment.or(byHumanities).or(bySocialSciences).or(byTopics).or(byOther))
$w('#dataset1').setFilter(newFilter);
lastFilterExpertise = expertise;
lastFilterCategory = category;
}
}
function loadACFreelancers() {
wixData.query('ACFreelancers')
.find()
.then(res => {
let options = [{"value": '', "label": 'All Categories'}];
options.push(...res.items.map(expertise => {
return {"value": expertise.category, "label": expertise.category};
}));
$w('iCategory').options = options;
});
}