Context…
I have two dropdowns to filter a gallery full of articles. One filters by category (manual input in settings, mapped to a field in dataset). One is a full, long list of all articles (linked to a field in the dataset) for people who don’t want to scroll through the images. I also have a reset button.
Problem…
The category dropdown works fine. The list dropdown works to select any single articles, but the “All” item doesn’t work. After filtering single articles, when I tap ‘All’, the gallery goes blank.
Is there a way to make the “All” work by code? Or to remove it?
I’ve added my code below.
// BROWSE DROPDOWNS & RESET BUTTONS
import wixData from 'wix-data';
$w.onReady(function () {
// 1. BROWSE ARTICLES USING DROPDOWNS
$w('#categoryArticlesDropdown, #articlesListDropdown').onChange(() => {
const selectedVal1 = $w('#categoryArticlesDropdown').value;
const selectedVal2 = $w('#articlesListDropdown').value;
let filter = wixData.filter();
if (selectedVal1.length > 0 || selectedVal2.length > 0) {
if (selectedVal1.length > 0) {
const categoryTags = selectedVal1.split(",");
filter = filter.hasSome("category", categoryTags);
}
if (selectedVal2.length > 0) {
filter = filter.contains("heading", selectedVal2);
}
}
$w('#articlesDataset').setFilter(filter);
});
// 2. RESET ARTICLES FILTER
$w("#resetArticlesButton").onClick(function () {
$w('#articlesDataset').setFilter(wixData.filter());
$w('#categoryArticlesDropdown').value = undefined;
$w('#articlesListDropdown').value = undefined;
});
});