Like Shady, I’m back again.
What I have: A repeater showing restaurants/bars. These objects are tagged with 3 properties, such as Type of Place and Best For (could be romantic, nightlife, etc.).
The user can filter the repeater based on these 3 properties using checkboxes. I’m currently using a query search using a .contains as well as 2 .and conditions (see code below)
So far so good.
The problem: If a user checks the “Restaurant” option in the Type of Place checkbox and the "Café option, the repeater turns up empty. This is because I don’t have places that have both these properties.
What I want to happen is of course to show places that are tagged with “Restaurant” or with "Café.
So why not just use the .or function instead of the .and function? Well, when I try that, the repeater never filters, because even unchecked checkboxes have a value (even if it’s zero). So checking Restaurants only will still show cafés in the repeater.
My code:
export function searchButton_click(event) {
search();
}
function search() {
wixData.query("Courses")
.contains("bstFr", String($w('#vibeGroupBox').value))
.and(wixData.query("Courses").contains("typ", String($w('#typeGroupBox').value)))
.and(wixData.query("Courses").contains("soltagg", String($w('#sunshineGroupBox').value)))
.and(wixData.query("Courses").contains("stad", "Stockholm"))
.find()
.then(results => {
$w("#restRepeater").data = results.items;
});
}
I’m guessing what I need is some sort of if statement, specifying that the .or search should only be applied to checkboxes that are actually checked.
I’ve tried some if (checkbox.length > 0) but I don’t get it to work.
Appreciate any feedback.
Bonus Question:
$w.onReady(async function (){
$w('#restRepeater').onItemReady(($item, $itemData, index)=>{
$item('#button1').link = $itemData['uteserveringar/title']
})
I’m trying to connect a button in the repeater to a dynamic page corresponding to the item in the repeater. This line of code did not do the work. Any input here?