Hi everyone, I made a dropdown menu that filters by categories. Is it possible to choose a category as set by default?
I would like to select the Covid category as default.
I leave here the code I used, I also have a search bar in addition to the dropdown menu
import wixData from ‘wix-data’ ;
$w.onReady(() => {
wixData.query( ‘categorie’ )
.find()
.then(res => {
let options = [{ “value” : ‘’ , ‘label’ : ‘Tutti i prodotti’ } ] ;
options.push(…res.items.map(categoria => {
return { ‘value’ : categoria.title, ‘label’ : categoria.title};
}));
$w( ‘#dropdown1’ ).options = options;
})
});
let debounceTimer;
export function searchbar_keyPress_1(event, $w) { //enable onKeypress for input form
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w( “#searchbar” ).value, lastFilterCategoria); //ID of input form
}, 200 );
}
let lastFilterTitle;
let lastFilterCategoria;
function filter (title, categoria) {
if (lastFilterTitle !== title || lastFilterCategoria !== categoria) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains( ‘title’ , title);
if (categoria)
newFilter = newFilter.eq ( ‘categoria’ ,categoria);
$w( “#dataset1” ).setFilter(newFilter);
lastFilterTitle = title;
lastFilterCategoria = categoria;
}
}
export function dropdown1_change(event,$w) {
filter(lastFilterTitle, $w( ‘#dropdown1’ ).value);
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:
}