Need help with creating a search bar and a drop down filter that connects to a wix database.

Here is the link to my page:
https://pnitake.wixsite.com/mysite-1/cofa

My objective:

  • Utilize the drop down menu to filter.
  • Connect the search bar to a database.
  • I’d like the repeater to ONLY display the content if the title is typed in correctly.
  • And I’d like the repeater button to correspond to the searched item.

My current problems:

  • Something is wrong with my code.
  • Search bar is not working properly.
  • Drop down menu is not working properly.
  • The button is somehow linked to the same PDF file no matter what is searched, and no matter what is selected in the drop down menu.

Here is my current code:
import wixData from “wix-data” ;

$w.onReady(() => {
loadLabels();
});

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

export function iLabel_change(event, $w) {
filter(lastFilterTitle, $w( ‘#iLabel’ ).value);
}

function filter(title, continent) {
if (lastFilterTitle !== ‘title’ || lastFilterLabel !== ‘label’ ) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains( ‘title’ , title);
if (continent)
newFilter = newFilter.contains( ‘label’ , continent);
$w( ‘#dataset1’ ).setFilter(newFilter);
lastFilterTitle = title;
lastFilterLabel = ‘label’ ;
}
}

function loadLabels() {
wixData.query( ‘Labels’ )
.find()
.then(res => {
let options = [{ “value” : ‘’ , “label” : ‘All Labels’ }];
options.push(…res.items.map(label => {
return { “value” : label.title, “label” : label.title};
}));
$w( ‘iLabel’ ).options = options; (ERROR MESSAGE ON THIS LINE)
});

}

Any help or tips would be greatly appreciated! Thank you!

Well, for one thing, you are missing the hashtag in the screen element ID:

$w('#iLabel').options = options;             (*ERROR MESSAGE ON THIS LINE*)

I tried that as well, an error message still pops up for some reason. Not sure why.

It appears that you don’t have a screen element with the ID of #iLabel.

@yisrael-wix Thank you Yisrael, how can I add a screen element with the #iLabel ID? The #iLabel is the name of my dropdown menu.

@pnitake Perhaps you should better show your setup in a screenshot, where your dropdown & and it’s → ID can be seen. Anybody can see, what you have in front of your eyes.

@russian-dima Great idea, please see the attached images. Thank you.

@pnitake
Like it seems your problem still not solved?
Do you use —> EDITOR-X ?

@russian-dima Correct, I still need help. I’d be willing to pay you if I could make you a website designer and you could fix it.
Sorry, I don’t use Editor-X, I just use Wix, Dev-Mode, database, etc.

@pnitake Ok, no editor-X → good :sweat_smile:.
I will try to find time to help you to solve your problem.
(P.S. → You have got mail.)