This is a god awful mash up but I don’t know how to improve it from here… any pointers would be welcome
I have a repeater with items in it, and two filters applied:
-
Tag filtering, which filters by repopulating the repeater
-
Input field filtering, which filters by setFilter
So the tag filter works great, but I can’t get the input field to behave - it’ll randomly show all, or I have to type and retype… eventually the right items will show up if I type and delete enough, but I want them to work together and not be a janky hack.
Page is here: https://www.antscihub .com/caresheets
The collection name is Caresheets
The field the tags look for and filter is caresheetTags
The tag box is #tag
The repeater is #csRepeater
The search box is #iLocation
The dataset is #csdb
The field the input box is searching is overviewRange
I’m not sure if this is within the scope of this post, so please let me know if it is not. Thank you for taking a look!
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixData from 'wix-data';
const collectionName = 'Caresheets';
const fieldToFilterByInCollection = 'caresheetTags';
$w.onReady(function () {
//TODO: write your page related code here...
setRepeatedItemsInRepeater()
loadDataToRepeater()
$w('#tags').onChange((event) => {
const selectedTags = $w('#tags').value
loadDataToRepeater(selectedTags)
})
});
function loadDataToRepeater(selectedCategories = []) {
let dataQuery = wixData.query(collectionName)
if (selectedCategories.length > 0) {
dataQuery = dataQuery.hasAll(fieldToFilterByInCollection, selectedCategories)
}
dataQuery
.find()
.then(results => {
const itemsReadyForRepeater = results.items
$w('#csRepeater').data = itemsReadyForRepeater;
const isRepeaterEmpty = itemsReadyForRepeater.length === 0
if (isRepeaterEmpty) {
// $w('#noResultsFound').show()
} else {
// $w('#noResultsFound').hide()
}
})
}
let debounceTimer;
export function iLocation_keyPress_1(event, $w) {
console.log($w('#iLocation').value);
filter($w('#iLocation').value);
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iLocation').value);
}, 200);
}
let lastFilterLocation
function filter(range) {
if (lastFilterLocation !== range) {
$w('#csdb').setFilter(wixData.filter().contains('overviewRange', range));
lastFilterLocation = range;
}
}
function setRepeatedItemsInRepeater() {
$w('#csRepeater').onItemReady(($item, itemData) => {
$item('#csRepeaterSpecies').text = itemData.species;
})
}