I know that I can do OR statements, but how do I chain several of these together?
Here is a screenshot of the page I’m working on. Each title is a field name in my collection, and each check box are the values in those fields.
My rudimentary attempt was to use IF statements for checked or unchecked states, then “add” onto the filter. Please take a look, any help would be appreciated.
import wixData from ‘wix-data’;
var kwFilter;
export function applyFilterButton_click(event, $w) {
For anyone wondering, I got this all sorted out very neatly.
The trick is to not use the OR or NOT statements in your query. You can’t chain those together to create a “complex” user selected query like you see in the image I originally posted.
If a product attribute column is never empty, as in it must have an attribute, use hasSome. hasSome takes an array, so all you have to do is create an empty array, use logic to see if the checkbox is checked, and if it is, push it into the array. Here’s an example:
(KEY NOTE: hasSome is an EXACT comparison, so make sure you push in the exact result you wish to query)
If a product attribute column is a simple Yes or No, just use .contains(“attribute”, “Yes”); or something along those lines.
So in short, you just keep doing that for each attribute you’re trying to query. If you look at the query API, you’ll see that you can just keep adding on search parameters to it, so all you need to do is superQuery = superQuery.hasSome(“attribute”, attributeArray). You just keep stacking it on. My problems came from using the OR or NOT statements, because you can’t keep stacking those on. Its “easier” to just use if/else statements or Switch Cases to do the logic then add them to the query.
When its all said and done, you just do the normal query.find() and thats it. The query results were used to fill up a gallery. I recommend using Wix Pro galleries since there’s no actual limit to how many results it will load. Just remember the default is 50 if you don’t set a limit beyond that.
Any chance you can help me out with my coding? I am working on the same thing but cannot get my coding to load on the preview page… Do you have an email??
The reason I haven’t posted any code is because a lot of the data/information there is protected under an agreement I have with my client. If you have any questions about specific parts of your code, I can help the best I can.
Maybe involving “on change” to trigger both changing the value and mimic a search button click to update the results will work, try with one and replicate for other check boxes, good luck.