Help with search filter and dropdown please?!

Hello All,
First post here. I have spent three days trying to solve this problem, which I am sure is a simple fix, but have not been able to get it to work. I am trying to build a dictionary. The search bar would allow you to search for a word while the drop-down allows you to select a first letter of words.

I have a page with a repeater linked to database “Marine Corps Slang & Acronyms” drawing from columns titled “title” and “definition”
I created a second database collection called “123” that contains the alphabet
Both are added as datasets Read Only datasets to the page as dataset1 and dataset2 respectively
The input box is “iTitle” while the drop-down is “firstLetter”
I want to be able to search by title and first letter

Right now, the dropdown list is populated but nothing occurs when selected. Previously I had this working in the editor, but not on the live site. Can anyone point me in the right direction?

import wixData from "wix-data";

$w.onReady(()=> {
    wixData.query('123')
      .find()
      .then(res => {
 let options = [{"value": '','label':'All Letters'}];
          options.push(...res.items.map(firstLetter => {
 return {'value':firstLetter.title,'label': firstLetter.title};
          }));
          $w('#firstLetter').options = options;
      })
});

let lastFilterTitle;
let lastFilterLetter;

let debounceTimer;
export function iTitle_keyPress(event,$w){
 if (debounceTimer) {
        clearTimeout(debounceTimer);
        debounceTimer = undefined; 
    }
    debounceTimer = setTimeout(() =>{
    filter($w('#iTitle').value, lastFilterLetter);
    },200);
}

function filter(title,letter) {
 if (lastFilterTitle !== title || lastFilterLetter !== letter) {
 let newFilter = wixData.filter();
 if (title)
          newFilter = newFilter.contains('title', title);
 if (letter) 
          newFilter = newFilter.eq('firstLetter', letter)
    $w('#dataset1').setFilter(newFilter);
    lastFilterTitle = title;
    lastFilterLetter = letter;
    }
} 

export function FirstLetter_change(event, $w) {
    filter(lastFilterLetter, $w('#firstLetter').value);
}

If this is working in Preview and not on Live, make sure that you have the correct collection permissions and that you have synced the sandbox collection to Live .

Yisrael,
The dropdown went from working in editor to not working at all in the editor without any changes made to the code. Same with the live site. I had it working Thursday evening on both sides, but it was broken by Friday night without any changes.

Databases are set to read. Code was copied from a Wix video verbatim.
URL: https://www.beforethecorps .com/slang

Any help is greatly appreciated.

-Andrew

Nothing to do with Preview/Live… You have not connected the FirstLetter_change() event handler to the Dropdown:

@yisrael-wix I knew it was something embarassingly simple. Thank you for catching that and the help. One quick follow-up question - when the dropdown menu loads, it shows a blank selection as its default and not the “All Letters” option, although it functions the same.

All Letters works when selected, but doesn’t appear as the list default.

Thanks again!

@yisrael-wix Once again, without making changes to the site code, the dropdown stopped working. The only things that were done was the addition of content to the content manager. No settings were changed.

After reviewing the code, I saw the event handler had disconnected, as had some sort functions. I fixed that, but the dropdown does not function properly still on the live site or in the editor.

There are two issues:

  1. The “All Letters” value does not show itself as the default value (nor does it show itself when clicked)
  2. the list doesn’t reset well on-click. When selecting a letter from the drop down, it seems to arbitrarily remove some options from the list. It will either show only a fraction of the available options or none, and it will no longer alphabetize them. I have checked the write settings and the sorting functions on both datasets.