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 🖐
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