Hi WiX Community! I’m creating a website for my master’s project / thesis. I want to use multiple checkboxes to filter a repeater similar to this webpage https://www.routetoresilience.co.uk/services.
Based on the info that I have found in the forums, vids, and articles, I think using Boolean values to filter will be “easier” for me since I am new to coding and I will also be using multiple checkboxes. I’ve seen this forum post and tried using the code https://www.wix.com/code/home/forum/community-discussion/multiple-checkbox-filter-problem and used the example from this page https://www.vorbly.com/Vorbly-Code/WIX-REPEATER-MULTIPLE-CHECKBOX-FILTERS to set up my test page with info. They seem to have similar code but for some reason when I try to filter and deselect checkboxes the repeater that shouldn’t appear is showing up, the opposite of what I want it to do. I’ve tried playing around with the onClick() and checkbox_changed() functions but have reached a dead end.
What I currently have:
- A test page https://rsenoren.wixsite.com/mysite/test-store-page with test info.
- A dataset called “Products”
- A page with a repeater that is NOT connected to the dataset, but the elements are connected to the dataset.
- 3 checkboxes (for now until I manage to get multiple checkboxes to filter)
Thank you in advance for your help!
Here is the code that I am using:
import wixData from ‘wix-data’;
function ProductFilter() {
wixData.query(“Products”)
.eq(“duration”, $w(“#checkbox1”).checked)
.or(
wixData.query(“Products”)
.eq(“boots”, $w(“#checkbox2”).checked)
)
.or(
wixData.query(“Products”)
.eq(“sneakers”, $w(“#checkbox3”).checked)
)
// add or statements for the other checkboxes
.find()
.then((results) => {
//console.log(results.items);
let Products = results.items;
$w(‘#repeater1’).data = Products;
})
}
// Query to get the information from the database
$w.onReady( function () {
ProductFilter();
$w('#repeater1').onItemReady(($w, itemData) => {
// Add here all the relevant elements of the repeater
$w(‘#text22’).text = itemData.title;
$w(‘#text24’).text = itemData.description;
$w(‘#image12’).src = itemData.image;
});
});
// What does this statement mean to connect the onClick() for the checkbox_changed() below?–>“And then connect the onClick() function of all of the Checkbox components to this function:”
// And then connect the onClick() function of all of the Checkbox components to this function:
export function checkbox_changed(event, $w) {
ProductFilter();
}
export function checkbox1_click(event, $w) {
checkbox_changed();
}
export function checkbox2_click(event, $w) {
checkbox_changed();
}
export function checkbox3_click(event, $w) {
checkbox_changed();