Error in adding third search element to Search a Database

Hi Wix community!

I am new to Wix code but have studied/followed the great resources here about how to allow users to search a database on an index page:

I’ve created an Index Page with a table linked to a dataset that would allow users to search by: 1) Keyword Title Search, 2) Dropdown search by Topic, and 3) Dropdown search by Resource Type.

Following the examples/code above, I was able to successfully get the code for keyword search + dropdown search by topic to work. However, I’ve been stuck when incorporating the third element, a dropdown search by Resource Type – my code below is still not working.

I think the error might be something in the “function filter” section of the code. I am not sure if I am allowed to add more than two items for this section of the code, because the first two items (title, topic) work — just not the “type” part. Please see below.

If anyone might be able to help pinpoint what I am doing wrong, I’d greatly appreciate your help. Thank you in advance!

import wixData from ‘wix-data’;

$w.onReady(() => {
loadTopics();
loadTypes();
});

let lastFilterTitle;
let lastFilterTopic;
let lastFilterType;

let debounceTimer;

export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iTitle’).value, lastFilterTopic, lastFilterType);
}, 500);
}

export function iTopic_change(event, $w) {
filter(lastFilterTopic, $w(‘#iTopic’).value);
}

export function iType_change(event, $w) {
filter(lastFilterType, $w(‘#iType’).value);
}

// I THINK THIS IS WHERE THE ERROR MIGHT BE. AM I LIMITED TO JUST TWO ITEMS FOR THIS SECTION?
function filter(title, topic, type) {
if (lastFilterTitle !== title || lastFilterTopic !== topic || lastFilterType !== type) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘title’, title);
if (topic)
newFilter = newFilter.contains(‘topic’, topic);
if (type)
newFilter = newFilter.contains(‘type’, type);
$w(‘#dynamicDataset’).setFilter(newFilter);
lastFilterTitle = title;
lastFilterTopic = topic;
lastFilterType = type;
}
}

function loadTopics() {
wixData.query(‘Topic’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”: ‘All Topics’}];
options.push(…res.items.map(topic => {
return {“value”: topic.title, “label”: topic.title};
}));
$w(‘#iTopic’).options = options;
});
}

function loadTypes() {
wixData.query(‘Type’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”: ‘All Resource Types’}];
options.push(…res.items.map(type => {
return {“value”: type.title, “label”: type.title};
}));
$w(‘#iType’).options = options;
});
}