Here is problem I am having with a drop down that works with text search input for repeater. All works great except this duplication of all categories (every database entry creates another category drop down, rather then just being a single entry). So database entries that fall under same category as another entry just creates a duplicate category entry within the drop down. Not sure how to edit my code to make it a set list of categories without the duplication (I would have anywhere from 10 to 25 depending on how big of an issue I run into in creating this in code list.
Here is my code and I assume I have to work in the list to the query under the onReady…?? Reference is field used in text search box, and Category is field used in the drop down box.
It is set up with standard repeater from Lists & Grids
import wixData from “wix-data”;
$w.onReady(() => {
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;
});
});
let lastFilterReference;
let lastFilterCategory;
let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(“#iTitle”).value, lastFilterCategory);
}, 200);
}
function filter(reference, category) {
if (lastFilterReference !==reference || lastFilterCategory !== category) {
let newFilter = wixData.filter();
if (reference)
newFilter = newFilter.contains(‘reference’, reference);
if (category)
newFilter = newFilter.eq(‘category’, category);
$w(“#dataset1”).setFilter(newFilter);
lastFilterReference = reference;
lastFilterCategory = category;
}
}
export function iCategory_change(event, $w) {
filter(lastFilterReference, $w(“#iCategory”).value);
}