I’ve been able to set up multiple field filtering like so:
function filter() {
$w(“#submissions”).setFilter(wixData.filter()
.hasSome(‘format’, formAny)
.and(wixData.filter()
.hasSome(‘genre’, genAny)
.and(wixData.filter()
.hasSome(‘protagonist’, protAny)))
)}
I have formAny etc. set to = the relevant checkboxgroup.value, which works.
But I can’t figure out how to include items where the field is empty, when the input has no value. I can set formAny etc. to = the values of all the checkboxgroup.options (if no options are selected) to include those that match any of the possible options, but I can’t see a way to include empty fields.
If I need to I can potentially have an additional tag to represent ‘none’, but I feel like there’s got to be another way.
Any thoughts?
@jonatandor35 Thanks so much, it makes a lot of sense and works now!
!== ‘undefined’ didn’t seem to do the trick, but since this showed me how to use if statements in a filter I got it working with .length >0
And I use .hasSome() since they are checkboxgroups with multiple values, perhaps my explanation didn’t make that clear.
@rackabello You’re welcome. Whether to use “undefined” or “false” or “null” or an empty string or something else depends on the the values. Maybe in other cases you’ll need the “undefined”.
Your explanation regarding the checkboxGroups is crystal clear now.