Hi - I’ve set up a dropdown filter and input box to filter a repeater. However the input search field only works if it is used the first time on the page, ie if I’ve tried to filter by dropdown filter and then a new search with input search it doesn’t work. I’ve set a clear search button which clears. The input field also doesn’t clear previous searches which I would like it to do. Could anyone help please.
Thanks.
import wixData from "wix-data";
$w.onReady(function () {
$w("#image37").fitMode = "fit";
});
$w.onReady(() => {
loadExternalLinksType();
});
let lastFilterTitle;
let lastFilterType;
let debounceTimer;
export function iTitle_keyPress(event) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iTitle').value, lastFilterType);
}, 500);
}
export function iELType_change(event) {
filter(lastFilterTitle, $w('#iELType').value);
}
function filter(title, type) {
if (lastFilterTitle !== title || lastFilterType !== type) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains('name', title);
if (type)
newFilter = newFilter.contains('type', type);
$w('#dataset2').setFilter(newFilter);
lastFilterTitle = title;
lastFilterType = type;
}
}
function loadExternalLinksType() {
wixData.query('ExternalLinksType')
.find()
.then(res => {
let options = [{"value": '', "label": 'All'}];
options.push(...res.items.map(type => {
return {"value": type.title, "label": type.title};
}));
$w('#iELType').options = options;
});
}
export function clear_click(event) {
$w("#iELType").placeholder = "All";
$w("#iELType").value = null;
$w("#iTitle").value = "";
$w("#iTitle").resetValidityIndication();
$w("#dataset2").setFilter(wixData.filter());
}