Taking data from database while filling the input


#1

Hi there!
I have a question to you. Is it possible to use Meteor in that use:

I have an input on my site, for example: to fill in a name.
When I push “M” buton, for example, I want to have a return from my database (collection) some names which start on “M”. Something like a prompt under my input - I could pass between those names with keys, pushing enter accept one of those returned names and fill the input.

That’s someting like a search in your web browser :slight_smile:


#2

I’m interested in this answer too. In fact, I am looking for fuzzy search. It looks like twitter typeaheadJS has this functionality, and there is a meteor package, but I’m looking for something a little lighter weight and without the bootstrap styling.


#3

I also noticed someone is working on a project - Easy Search which looks like it may work.


#4

Sorry for all the posts. Here is what I just worked out for my project. Create a reactive var for your Template:

Template.mytemplate.created = function () {
    this.searchString = new ReactiveVar("");
};

Then use this in your helper for dynamic/reactive search:

Template.mytemplate.helpers({
  items: function () {
    var searchString = Template.instance().searchString.get();
    var regExSearch = new RegEx(searchString, "i");
    return Items.find({name: {$regex: regExSearch}});
  }
});

This will match anywhere in the word. If you only want to match in the beginning, use an anchor at the start of your RegEx search (e.g. RegEx('^' + searchString, "i") )

Finally, register an event to listen to the keypress event and update your searchString reactive var. This seems to be working perfectly for me.


#5

#6

easysearch, typeahead, mizzao:autocomplete etc… etc
But autoform is fully integrated with select2, so that one is probably the best practice if you plan to have some forms on site.


#7

May you add your code here? I don’t know what to add in my HTML file, how to add a listener to the keypress…
I’m new to that, sorry.