Help with using correct code.

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!

Hi Nathaniel,

In Javascript, “=” is considered an assignment operator. When you are comparing two values, wanting to know if they equal each other in this case, use “===” instead.

Be sure and pay attention to the red dot you should be seeing in your page code:

When you hover the mouse over the red dot, you get more information about what the problem is.

Now I feel silly, forgot JS 101. Thanks for the help!

I’m still having trouble getting everything to display, currently my ideas for that are blocking everything. Is there a different expression that could be used to show everything? Thanks!

@nathanael

$w("#dataset1").setFilter( wixData.filter() );

@tony-brunsman Ok, that was my initial thought. I have it set under two different triggers and I forgot to update the second one. Once I did that it worked! Thank you very much!