I have created a couple of filters for my site. I have two of them working, but the third one is not. I cannot figure out what I am doing wrong. Could you please review my code and let me know where the error is.
I am filtering on student names, student birthdays and what program they are in. The filter for the names and program is working but I can not filter on birthday dates. I am trying to get a list of student birthdays for a given month.
Thanks in advance for your help.
Bill
Here is my code.
import wixData from “wix-data”;
$w.onReady(() => {
loadProgram();
});
let lastFilterStudentName;
let lastFilterStudentBirthday;
let lastFilterProgram;
let debounceTimer;
export function istudentName_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#istudentName’).value, lastFilterStudentBirthday, lastFilterProgram);
}, 200);
}
export function istudentBirthday_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter(lastFilterStudentName, $w(‘#istudentBirthday’).value, lastFilterProgram);
}, 200);
}
export function iprogram_change_1(event, $w) {
filter(lastFilterStudentName, lastFilterStudentBirthday, $w(‘#iprogram’).value);
}
function filter(studentName, studentBirthday, program) {
if (lastFilterStudentName !== studentName || lastFilterStudentBirthday !== studentBirthday || lastFilterProgram !== program) {
let newFilter = wixData.filter();
if (studentName)
newFilter = newFilter.contains(‘studentName’, studentName);
if (studentBirthday)
newFilter = newFilter.contains(‘studentBirthday’, studentBirthday);
if (program)
newFilter = newFilter.eq(‘program’, program);
$w('#dataset1').setFilter(newFilter);
lastFilterStudentName = studentName;
lastFilterStudentBirthday = studentBirthday;
lastFilterProgram = program;
}
}
function loadProgram() {
wixData.query(‘program’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”: ‘All Programs’}];
options.push(…res.items.map(program => {
return {“value”: program.title, “label”: program.title};
}));
$w(‘#iprogram’).options = options;
});
}