Yeah that part is giving me an error because I don’t know the correct syntax to filter by multiple fields in the collection or if it’s even possible.
This is the code I got from another post that worked when I had only 1 selection tag (location) set up. Example: When I click on the “Canada” selection tag button, then the repeater filters to show only results that are located in Canada. I want to add another separate filter that can look for type of service as well. Example: Click “mental health” for one filter and “Canada” in another filter to show only items in the collection that are mental health services located in Canada.
import wixData from 'wix-data';
const collectionName = 'MentalHealthResources';
const fieldToFilterByInCollection = 'location';
$w.onReady(function () {
setRepeatedItemsInRepeater();
loadDataToRepeater();
$w('#locationtags').onChange((event) => {
const selectedTags = $w('#locationtags').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('#repeater').data = itemsReadyForRepeater;
const isRepeaterEmpty = itemsReadyForRepeater.length === 0
if (isRepeaterEmpty) {
$w('#noResultsFound').show();
} else {
$w('#noResultsFound').hide();
}
})
}
function setRepeatedItemsInRepeater() {
$w('#repeater').onItemReady(($item, itemData) => {
$item('#name').src = itemData.name;
$item('#description').tooltip = itemData.description;
$item('#button').text = itemData.button
})
}