I have four search buttons, and the one for Year isn’t working; the one for Title gives a message that says, please fill out this field; and as you can see I have a button to clear the boxes, but in the Series box it always shows the first one, so it is not clearing.
Here is the code:
Import wixData from “wix-data” ;
$w.onReady(() => {
loadBooks();
});
let lastFilterTitle;
let lastFilterBook;
let lastFilterYear;
let lastFilterSeries;
let debounceTimer;
export function iTitle_keyPress (event) {
$w( “#loadingGif” ).show();
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout (() => {
filter($w( ‘#iTitle’ ).value, lastFilterBook, lastFilterYear, lastFilterSeries)
$w( “#loadingGif” ).hide();
}, 200 );}
export function iBook_change(event) {
$w( “#loadingGif” ).show();
filter(lastFilterTitle, $w( ‘#iBook’ ).value, lastFilterYear);
setTimeout( function () {
$w( “#loadingGif” ).hide();
}, 700 );
}
export function yearDropdown_change(event) {
$w( “#loadingGif” ).show();
let myValue = $w( ‘#yearDropdown’ ).value;
console.log(myValue, “myValue” )
$w( “#dynamicDataset” ).setFilter(wixData.filter().eq( ‘year’ , myValue));
setTimeout( function () {
$w( “#loadingGif” ).hide();
}, 7000 );
}
function filter(title,book,year,series) {
if (lastFilterTitle !== title ||
lastFilterBook !== book ||
lastFilterYear !== year ||
lastFilterSeries !== series) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains( ‘title’ , title);
if (book)
newFilter = newFilter.contains( ‘book’ , book);
if (year)
newFilter = newFilter.contains( ‘year’ , year);
if (series)
newFilter = newFilter.contains( ‘series’ , series)
$w( ‘#dynamicDataset’ ).setFilter(newFilter);
lastFilterTitle = title;
lastFilterBook = book;
lastFilterYear = year;
lastFilterSeries = series;
}
}
function loadBooks() {
wixData.query( ‘Books’ )
.find()
.then(res => {
let options = [{ “value” : ‘’ , “label” : ‘All Books’ }];
options.push(…res.items.map(books => {
return { “value” : books.book, “label” : books.book};
}));
$w( ‘#iBook’ ).options = options;
});
}
export function seriesDropdown_change(event) {
$w( “#loadingGif” ).show();
filter(lastFilterTitle, lastFilterBook, lastFilterYear, $w( ‘#seriesDropdown’ ).value);
setTimeout( function () {
$w( “#loadingGif” ).hide();
}, 7000 );
}
export function clearbutton_click(event) {
// Add your code for this event here:
$w( “#iTitle” ).value= “” ;
$w( “#iBook” ).selectedIndex= 0 ;
$w( “#yearDropdown” ).value= “” ;
$w( “#seriesDropdown” ).selectedIndex= 0 ;
}