Delay search event searchbar

Easy peasy question:

This is the classic template of searchbar:

var searchbar = $f7.searchbar.create({
                el: '.searchbar',
                searchContainer: '.list',
                searchIn: '.item-title',
                on: {
                            run_my_search(query)
                    }
                }
            });

I would like to know if there is the possibility to delay the on event like this (this is my old code of other project):

$('input[name="search"]').keyup(delay(async function (e) {
    let query = $$('input[name="search"]').val()
    run_my_search(query_restaurant_name)    
}, 500));

The main idea is not to launch a search at each typing, but to leave the time to type at least a few characters to the user (to save resources and server-side rest calls).
I didn’t find anything in the doc

Yes, you can do the same here, this is how JS works in general :slight_smile:

on: {
  search: delay((searchbar, query) => {
    // do something
  }, 500)
}
1 Like

You can use lodash debounce for this Lodash Documentation

I’ve tried the same things, but I had a typo… So I got panic and asked the question LMAO… Thanks

1 Like

What can be the reason for

$f7.searchbar.create({
                el: '.searchbar' [..] ```

works, but if I try let searchbar = $f7.searchbar.get('.searchbar') I always get undefined? This pieace of code is always inside pageInit