How to reset my my dropdown to show all items

Hi Community,

I am running in circles right now. On my website www.swiss-medtech.ch/weiterbildung I have imlemented a user input form as well as a dropdown form. Both work together like a charm. The reset button also cleares the content and sets it back where I started from BUT somehow it still remembers my last dropdown choice.

In case someone is out there who can help me solve this issue and close to Switzerland “DRINKS ARE ON ME”!!!

Here is the Code I am using:

import wixData from ‘wix-data’;

$w.onReady(() => {
wixData.query(‘art’)
.find()
.then(res => {
let options = [{“value”: ‘’, ‘label’: ‘Alle Arten’}];
options.push(…res.items.map(art => {
return {‘value’: art.title, ‘label’: art.title};
}));
$w(‘#iContinent’).options = options;

    }) 

});

let lastFiltertitle;
let lastFilterArt;
let lastFilterOrt;

let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iTitle’).value, lastFilterArt, lastFilterOrt);
}, 200);
}

function filter(title, art, ort) {
if (lastFiltertitle !== title || lastFilterArt !== art || lastFilterOrt !== ort) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘bezeichnung’, title);
if (art)
newFilter = newFilter.eq(‘art’, art);
if (ort)
newFilter = newFilter.eq(‘ort’, ort);

$w(‘#dataset1’).setFilter(newFilter);
lastFiltertitle = title;
lastFilterArt = art;
lastFilterOrt = ort;
}
}

export function iContinent_change(event) {
filter(lastFiltertitle, $w(‘#iContinent’).value);

}

export function clearFilters_onClick() {
$w(“#dataset1”).setFilter(wixData.filter(undefined));
$w(“#iContinent”).placeholder = “Nach Art sortieren”;
$w(“#iContinent”).selectedIndex = undefined;
}

First make sure the Alle Arten has a value in your dropdown.

let options = [{"value": 0, 'label': 'Alle Arten'}];             options.push(...res.items.map(art => {  return {'value': art.title, 'label': art.title};             }));             $w('#iContinent').options = options;          }) });

Then in clearFilters just do

$w("#iContinent").value = 0;  

And it should restart by selecting the Alle Arten

This will reset the dropdown selection

$w(“#iContenent”).selectedIndex = undefined;

That the code he had that did not work right?

First of all, let me thank you very much for your help.

Unfortunately Andreas, When I enter 0 as a value for Alle Arten, it does not search the entire column in the database as the value does simply not exist in my database. In order to display “Alle Arten” I would need to tell the freaking database to show it all. Your code worked fine but when I want to reset and then type something it still searches within my last dropdown choice eventhough it says “Alle Arten”.

I dont know what to do…

export function iContinent_change(event) {     
let searchValue;
if ($w('#iContinent').value === 0) {
  searchValue = undefined;
} else {
  searchValue = $w('#iContinent').value;
}
filter(lastFiltertitle, searchValue);
   }

@andreas-kviby

Thanks, I have amended the code with it as you can see below and published it if you would like to give it a try. In the dropdownbox I have inserted “Alle Arten” and 0 as ists value. Unfortunately no luck. I am about to jump out the window :frowning:

import wixData from ‘wix-data’;

$w.onReady(() => {
wixData.query(‘art’)
.find()
.then(res => {
let options = [{“value”: 0, ‘label’: ‘Alle Arten’}];
options.push(…res.items.map(art => {
return {‘value’: art.title, ‘label’: art.title};
}));
$w(‘#iContinent’).options = options;

    }) 

});

let lastFiltertitle;
let lastFilterArt;
let lastFilterOrt;

let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iTitle’).value, lastFilterArt, lastFilterOrt);
}, 200);
}

function filter(title, art, ort) {
if (lastFiltertitle !== title || lastFilterArt !== art || lastFilterOrt !== ort) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘bezeichnung’, title);
if (art)
newFilter = newFilter.eq(‘art’, art);
if (ort)
newFilter = newFilter.eq(‘ort’, ort);

$w(‘#dataset1’).setFilter(newFilter);
lastFiltertitle = title;
lastFilterArt = art;
lastFilterOrt = ort;
}
}

export function iContinent_change(event) {
let searchValue;
if ($w(‘#iContinent’).value === 0) {
searchValue = undefined;
} else {
searchValue = $w(‘#iContinent’).value;
}
filter(lastFiltertitle, searchValue);
}

export function clearFilters_onClick() {
$w(“#dataset1”).setFilter(wixData.filter(undefined));
$w(“#iContinent”).value = 0;
}

@andreas-kviby issue I have ran into in using this is if you have a search box and drop down. The clr button will clear the search, but then only subsequent searches will work under that last dropdown used. Other dropdowns and search box will not function. Screen refresh is required to reset to full use.