Hi, I am attempting to create a page that lists all items from a dataset onto a repeater and then can be filtered using a search or a dropdown menu. I have it mostly working but I want to make it so that when the dropdown is set to all the filter is not applied.
I attempted to use an If Else statement but when I try I get an “unexpected constant addition” error. I am trying to set the “if” to my dropdown (dropdown1) giving a value of ‘All’ (which is configured as the value when all is selected from the dropdown) to then not applying the filter.
Here is my problematic code (with error underlined):
export function dropdown1_click(event) {
if ($w(‘#dropdown1’).value = ‘All’)
$w(‘#dataset1’).setFilter()
else {
let searchValue = $w(“#dropdown1”).value;
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘productType’, searchValue));
}
}
Is there another way I should reference this object or is there something wrong with my syntax? Also are there any recommendations for making this work better?
My entire page code for reference:
import wixData from ‘wix-data’;
$w.onReady( function () {
//TODO: write your page related code here…
});
export function input1_keyPress(event) {
let searchValue = $w(“#input1”).value;
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘title’, searchValue));
}
export function input1_change(event) {
let searchValue = $w(“#input1”).value;
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘title’, searchValue));
}
export function dropdown1_click(event) {
if ($w(‘#dropdown1’).value = ‘All’)
$w(‘#dataset1’).setFilter()
else {
let searchValue = $w(“#dropdown1”).value;
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘productType’, searchValue));
}
}
export function dropdown1_change(event) {
let searchValue = $w(“#dropdown1”).value;
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘productType’, searchValue));
}
Thank you for any help!