--- title: Provide suggestions for the Omnibox slug: '343' canonical_url: https://docs.coveo.com/en/343/ collection: javascript-search-framework source_format: adoc --- # Provide suggestions for the Omnibox The Omnibox provides an interface that any custom component can interact with and provide data to so that the `Omnibox` renders it. When the `Omnibox` needs data, it triggers a `populateOmnibox` event. To listen to this event and provide suggestions, a component needs to bind a function on the root of the search interface. The sections in this article describe the steps required to provide suggestions to the Omnibox. ## Binding to the root Set a reference to the root of your search interface by binding the `populateOmnibox` event and the `onPopulateOmnibox` function to the `searchInterface` root element using JQuery `$.on`. ```javascript var searchInterface = $("#mySearchInterface"); //This is the root element searchInterface.on("populateOmnibox" , onPopulateOmnibox); //root.on allows us to bind the event and our function. Here populateOmnibox is the event and onPopulateOmnibox is our function. ``` ## Implementing the onPopulateOmnibox function Implement the following code. This function will be executed every time the `populateOmnibox` event is triggered. ```javascript function onPopulateOmnibox (e , populateOmniboxObject){ // First we need to decide what we are searching for. // It's up to each component to decide what would suit best for their own need. For example, a facet will look for the whole content of the query box to provide suggestions. // Another custom component could instead decide to use only the active word (the position of the cursor in the query box). var wordToSearch = populateOmniboxObject.completeQueryExpression.word; var regexToSearch = populateOmniboxObject.completeQueryExpression.regex; // This is the main function that each custom component will need to implement. In this example, this function will be implemented in the next section. // Note that this would cover the case where you can immediately return HTML content. To perform an asynchronous call (for example, an Ajax request), see the // section "Populating Omnibox with content from an asynchronous call" of this page. var elementToReturn = buildOmniboxContent(regexToSearch, populateOmniboxObject); var objectToReturn = { zIndex: 100, //Arbitrary number used to determine where the row should render. > 50 will render before the facet. This value is optional. element : elementToReturn } // Use the populateOmniboxObject interface to push suggestions. populateOmniboxObject.rows.push(objectToReturn); } ``` ## Implementing the buildOmniboxContent function Implement the following code. This function is required and used in the `onPopulateOmnibox` function to build the `OmniboxComponent` custom content. This function will be custom for each custom component, and therefore can't be implemented in a general manner in this example. What's important to know is that the Omnibox expects two things: . It expects an HTML element (a div, a span, a table... Anything that's valid HTML will be added to the Omnibox). Note that if you provide complex markup, you might need to write quite a bit of custom CSS to render it properly. . To be able to navigate up/down with the keyboard like for the facet suggestions, each selectable section needs to have the "coveo-omnibox-selectable" CSS class. The Omnibox will scan for HTML sections with that CSS class to determine the next/previous keyboard navigation value. ```javascript function buildOmniboxContent(regex, populateOmniboxObject) { // This function won't be implemented in this example. Let's assume that it returns an array of values that correctly match the given regex. // The logic behind this function would be custom for each component. // For example, it could be a query to the Coveo index using the Search api var arrayOfValues = findValuesThatMatch(regex) // Let's assume that this component wants to build some kind of data table with its suggestions. // This is the kind of HTML structure that would indeed work very well with the Omnibox, without much customization. var table = $("