Filter with multiple checkboxes

Hey,
I want to create a filter with multiple checkboxes. The code workes, but if I have selected both checkboxes, only the items from the last selection will be shown.

The filter should show all items that are true in ‘boolean1’ or ‘boolean2’ in the dataset.

function test(event) {
 if ($w('#checkbox1').checked)$w('#dataset1').setFilter(wixData.filter().eq('boolean1', true))
 if ($w('#checkbox2').checked)$w('#dataset1').setFilter(wixData.filter().eq('boolean2', true))
}

export function checkbox1_click(event) {
    test()
}

export function checkbox2_click(event) {
    test()
}

Hi :raised_hand_with_fingers_splayed:

You need to check which checkbox is selected or both before applying the filter, one way to do it is with an if statement.

if ($w('#checkbox1').checked && !$w('#checkbox2').checked) {
    $w('#dataset1').setFilter(
        wixData.filter().eq('boolean1', true)
    )
} else if (!$w('#checkbox1').checked && $w('#checkbox2').checked {
    $w('#dataset1').setFilter(
        wixData.filter().eq('boolean2', true)
    )
} else if ($w('#checkbox1').checked && $w('#checkbox2').checked {
    $w('#dataset1').setFilter(
        wixData.filter()
            .eq('boolean1', true)
            .eq('boolean2', true)
    )
}

Hope this helps!~
Ahmad

Hey,
not exactly. Your code shows all items that have ‘boolean1’ and ‘boolean2’.
I need a code that shows me ‘boolean1’ or ‘boolean2’.

Another problem is, that I have 9 checkboxes. With this code it will be a bit complicated.

If you only want one checkbox, use radio buttons instead to select one option.
Or you can add a little code to un-check the other checkbox.

I’m looking for this: https://www.wix.com/code-examples/multi-groups-filter

View
Template

But here is no code

I opened the Template and everything looks fine - code included.