The typeahead.js plugin to make your inputs with autocomplete support packaged for meteor applications.
- Support fetching meteor collections as typeahead dataset
- Easy to bind auto-complete suggestions to input using
data-sourceattribute - Allow using meteor template to visualize auto-complete suggestion
- Support most typeahead.js use cases:
- Asynchronous data sources
- Prefetched JSON data source
- Multiple datasets
Turns given HTML <input[type="text"]/> into a typeahead.
element- is HTML input element.source- is optional custom data source function withfunction(query, sync, async)signature wherequeryis text entered in the input andsync,asyncare callback functions expectingsuggestionsargument to show in dropdown.
Activates typeahead behavior for all elements matched by given CSS selector. selector parameter defaults to '.typeahead'.
typeahead.js dataset(s) is specified as data attribute if you don't specify custom data source function in Meteor.typeahead call.
-
data-source- name of function defined as helper for your meteor template with typeahead input. Optionally you could specifycollection.propertyto automatically bind given meteor collection to your typeahead input -
data-sources- name of template helper function that returns array of typeahead datasets.data-setsis alias. Demo application has an example.
typeahead.js options are specified as data attributes in your input element. List of supported attributes:
-
data-highlight– Iftrue, when suggestions are rendered, pattern matches for the current query in text nodes will be wrapped in astrongelement withtt-highlightclass. Defaults tofalse. -
data-hint– Iffalse, the typeahead will not show a hint. Defaults totrue. -
data-min-length– The minimum character length needed before suggestions start getting rendered. Defaults to1. -
data-autoselect– Iftrue, the typeahead will select the first option when press enter key. Defaults tofalse. -
data-value-key- If the data-source returns objects, this can be used to set which attribute to use for the search text. If this is not specified, then it is assumed that each object will have an attribute namedvaluethat contains the search text.
Using data attributes you could specify handlers for corresponding typeahead opened, closed, selected, autocompleted events. Value of data attribute is name of template helper function to be used as event handler.
data-open- specifies handler for fortypeahead:openeventdata-close- specifies handler for fortypeahead:closeeventdata-select- specifies handler for fortypeahead:selecteventdata-autocomplete- specifies handler for fortypeahead:autocompleteevent
See also typeahead docs for custom events.