The typeToSearch
methods are used to control the type-to-search behavior.
typeToSearch.search()
Used to trigger a type-to-search query. This query will still respect the debounce and response timeout settings as defined in the getTypeToSearch
options.
Note: this function is called automatically on key press if bound to an input.
Parameters passed to the search
method:
NAME/TYPE | DESCRIPTION |
---|---|
string | The search term that will be used to find relevant products. |
TypeToSearchSearchOptions | The options that will control the behavior of the type-to-search query. |
typeToSearch.search() Options
The type-to-search search
method accepts the following options:
NAME/TYPE | DESCRIPTION |
---|---|
object | An object containing the contextual variables used for filters. Note: this context will be combined with the context used in the context property above |
| Note: for XGen rendered deployments only. The most recent key that was pressed on the keyboard. Used for tts activation settings. |
typeToSearch.bindInput()
Used to bind an HTML Input element to the type-to-search object. Any character the users types within that element will fire the search
method above on the set debounce.
Parameters passed to the bindInput
method:
NAME/TYPE | DESCRIPTION |
---|---|
HTMLInputElement | The HTML Input element that will be listened to for the user typing. |
Example
Binding a search input:
// Start a type to search session
const tts = getTypeToSearch(console.log, { deploymentId: '3d8e3aa4-b1e9-4b1b-9ff6-ca4bc64806d0' });
// Grab the input from the DOM
const inputElement = document.querySelector('input.searchInput');
// Bind the search input
tts.bindInput(inputElement);