
I’m trying to get the pink color as a result, how to write the code?
I use .or Query below, but the result is 1+1, show all items( all red & all size42 ). I only want to get red in size 42. How to do that? Thanks in advance!
import wixData from ‘wix-data’;
function ProductFilter() {
wixData.query(“Shoes1”)
.eq(“red”, $w(“#checkbox1”).checked)
.or(
wixData.query(“Shoes1”)
.eq(“size42”, $w(“#checkbox2”).checked)
)
.find()
.then((results) => {
console.log(results.items);
let Product = results.items;
$w(‘#repeater1’).data = Product
})
.catch((err) => {
let errorMsg = err;
console.log(errorMsg);
});
}
export function checkbox1_change(event) {
ProductFilter();
}
export function checkbox2_change(event) {
ProductFilter();
}
Hi.
You need to use and() condition.
Note that when chaining multiple WixData Filter functions to a query an add condition is assumed.
In your case, just remove or() and chain eq() as shown below:
.eq("red", $w("#checkbox1").checked)
.eq("size42", $w("#checkbox2").checked)
Good luck!
Many thanks! Sam. Finally got your answer! It works but only when both checkboxes are checked. If customer just check one of them, nothing show. Im looking forward to hearing from you! THANK YOU!
The and() filter gets only what meets both conditions. If you want to have several filters, you can follow this example: Checkbox Dropdown
Good luck!
@samuele Hi Sam, thanks for your reply! The sample you linked is also like 1+1+1…, not what im looking 4…
@samuele Hi Sam, what im looking 4 is: if just ‘red’ checkbox is checked, all red shoes show, if just ‘size42’ checkbox is checked, all size42 shoes show. if both checkboxes are checked, only show shoe size42 in red color. Plz help! Thank you!