# Coveo Omnibox Component (CoveoOmnibox)

The `Omnibox` component extends the `Querybox`, and thus provides the same basic options and behaviors. Furthermore, the `Omnibox` adds a type-ahead capability to the search input.

You can configure the type-ahead feature by enabling or disabling certain addons, which the Coveo JavaScript Search Framework provides out-of-the-box (see the `enableFieldAddon`, `enableQueryExtension`, and `enableQuerySuggestAddon` options).

Custom components and external code can also extend or customize the type-ahead feature and the query completion suggestions it provides by attaching their own handlers to the `populateOmniboxSuggestions` event.

See also the `Searchbox` component, which can automatically instantiate an `Omnibox` along with an optional SearchButton.

## Index

### Methods

- clear
- debugInfo
- disable
- enable
- getBindings
- getInput
- getText
- setText
- submit
- get

### Properties

- bind
- componentOptionsModel
- componentStateModel
- disabled
- logger
- queryController
- queryStateModel
- root
- searchInterface
- ID

### Accessors

- usageAnalytics

### Component Options

- clearFiltersOnNewQuery
- enableFieldAddon
- enableQueryExtensionAddon
- enableQuerySuggestAddon
- enableQuerySyntax
- enableSearchAsYouType
- inline
- numberOfSuggestions
- omniboxTimeout
- placeholder
- querySuggestCharacterThreshold
- searchAsYouTypeDelay

### Constructors

- constructor

## Methods

### clear

- clear(): void

- - Defined in ui/Omnibox/Omnibox.ts :370

  Clears the content of the input.

  #### Returns void

### debugInfo

- debugInfo(): any

- Inherited from BaseComponent.debugInfo

  - Defined in ui/Base/BaseComponent.ts :41

  Return the debug info about this component.

  #### Returns any

### disable

- disable(): void

- Inherited from BaseComponent.disable

  - Defined in ui/Base/BaseComponent.ts :52

  Disable the component. Normally this means that the component will not execute handlers for the framework events (query events, for example). Components are enabled by default on creation.

  #### Returns void

### enable

- enable(): void

- Inherited from BaseComponent.enable

  - Defined in ui/Base/BaseComponent.ts :61

  Enable the component. Normally this means that the component will execute handlers for the framework events (query events, for example). Components are enabled by default on creation.

  #### Returns void

### getBindings

- getBindings(): IComponentBindings

- Inherited from Component.getBindings

  - Defined in ui/Base/Component.ts :328

  Return the bindings, or environment, for the current component.

  #### Returns IComponentBindings

### getInput

- getInput(): HTMLInputElement

- - Defined in ui/Omnibox/Omnibox.ts :377

  Gets the `HTMLInputElement` of the Omnibox.

  #### Returns HTMLInputElement

### getText

- getText(): string

- - Defined in ui/Omnibox/Omnibox.ts :354

  Gets the current content of the input.

  #### Returns string

  The current content of the input.

### setText

- setText(text: string): void

- - Defined in ui/Omnibox/Omnibox.ts :362

  Sets the content of the input

  #### Parameters

  - ##### text: string

    The string to set in the input.

  #### Returns void

### submit

- submit(): void

- - Defined in ui/Omnibox/Omnibox.ts :341

  Adds the current content of the input to the query and triggers a query if the current content of the input has changed since last submit.

  Also logs a `searchboxSubmit` event in the usage analytics.

  #### Returns void

### Static get

- get(element: HTMLElement, componentClass?: any, noThrow?: boolean): BaseComponent

- Inherited from Component.get

  - Defined in ui/Base/Component.ts :410

  Get the bound component to the given HTMLElement. Throws an assert if the HTMLElement has no component bound, unless using the noThrow argument.
  If there is multiple component bound to the current HTMLElement, you must specify the component class.

  #### Parameters

  - ##### element: HTMLElement

    HTMLElement for which to get the bound component.

  - ##### Optional componentClass: any

    Optional component class. If the HTMLElement has multiple components bound, you must specify which one you are targeting.

  - ##### Optional noThrow: boolean

    Boolean option to tell the method to not throw on error.

  #### Returns BaseComponent

## Properties

### bind

bind: ComponentEvents

Inherited from Component.bind

- Defined in ui/Base/Component.ts :270

Allows the component to bind events and execute them only when it is enabled.

type

  {Coveo.ComponentEvents}

### componentOptionsModel

componentOptionsModel: ComponentOptionsModel

Inherited from Component.componentOptionsModel

- Defined in ui/Base/Component.ts :294

Contains the state of options for different components. Mainly used by ResultLink.

### componentStateModel

componentStateModel: ComponentStateModel

Inherited from Component.componentStateModel

- Defined in ui/Base/Component.ts :282

Contains the state of different components (enabled vs disabled). Allows to get/set values. Triggers component state event when modified. Each component can listen to those events.

### disabled

disabled: boolean

Inherited from BaseComponent.disabled

- Defined in ui/Base/BaseComponent.ts :23

A disabled component will not participate in the query, or listen to ComponentEvents.

type

  {boolean}

### logger

logger: Logger

Inherited from BaseComponent.logger

- Defined in ui/Base/BaseComponent.ts :18

Allows component to log in the dev console.

### queryController

queryController: QueryController

Inherited from Component.queryController

- Defined in ui/Base/Component.ts :286

Contains the singleton that allows to trigger queries.

### queryStateModel

queryStateModel: QueryStateModel

Inherited from Component.queryStateModel

- Defined in ui/Base/Component.ts :278

Contains the state of the query. Allows to get/set values. Trigger query state event when modified. Each component can listen to those events.

### root

root: HTMLElement

Inherited from Component.root

- Defined in ui/Base/Component.ts :274

A reference to the root HTMLElement (the SearchInterface).

### searchInterface

searchInterface: SearchInterface

Inherited from Component.searchInterface

- Defined in ui/Base/Component.ts :290

A reference to the root of every component, the SearchInterface.

### Static ID

ID: string

Inherited from BaseComponent.ID

- Defined in ui/Base/BaseComponent.ts :28

The static ID that each component needs in order to be identified.
For example, SearchButton -> static ID: SearchButton -> className: CoveoSearchButton

## Accessors

### usageAnalytics

- get (): IAnalyticsClient

- Inherited from Component.usageAnalytics

  - Defined in ui/Base/Component.ts :343

  A reference to the Analytics.client.

  #### Returns IAnalyticsClient

## Component Options

### clearFiltersOnNewQuery

clearFiltersOnNewQuery: boolean

- Defined in ui/Omnibox/Omnibox.ts :280

Whether to clear all active query filters when the end user submits a new query from the search box.

Note: This does not include the filter expression enforced by the currently selected tab, if any.

Default

  `false`

Available since

  September 2019 Release (v2.7023)

Markup configuration example(s) :

    data-clear-filters-on-new-query='true'
    data-clear-filters-on-new-query='false'

### enableFieldAddon

enableFieldAddon: boolean

- Defined in ui/Omnibox/Omnibox.ts :164

The `field` addon makes the `Omnibox` highlight and complete field syntax. Setting this option to `true` automatically sets the enableQuerySyntax option to `true` as a side effect.

Example:

> Suppose you want to search for PDF files. You start typing `@f` in the search box. The `Omnibox` provides you with several matching fields. You select the `@filetype` field. Then, you start typing `=p` in the input. This time, the `Omnibox` provides you with several matching values for the `@filetype` field. You select the `pdf` suggestion, and submit your search request. Since the `enableQuerySyntax` option is set to `true`, the Coveo Search API interprets the basic expression as query syntax and returns the items whose `@filetype` field matches the `pdf` value.

Default value is `false`.

Only effective when

  `enableQuerySyntax` is truthy

Default

  `false`

Markup configuration example(s) :

    data-enable-field-addon='true'
    data-enable-field-addon='false'

### enableQueryExtensionAddon

enableQueryExtensionAddon: boolean

- Defined in ui/Omnibox/Omnibox.ts :204

If Querybox.options.enableQuerySyntax is `true`, specifies whether to enable the `query extension` addon.

The `query extension` addon allows the Omnibox to complete the syntax for query extensions.

Default value is `false`.

Only effective when

  `enableQuerySyntax` is truthy

Default

  `false`

Markup configuration example(s) :

    data-enable-query-extension-addon='true'
    data-enable-query-extension-addon='false'

### enableQuerySuggestAddon

enableQuerySuggestAddon: boolean

- Defined in ui/Omnibox/Omnibox.ts :192

Whether to display Coveo Machine Learning (Coveo ML) query suggestions in the `Omnibox`.

A Coveo ML query suggestions (QS) model must be properly configured in your Coveo Cloud organization, otherwise this option has no effect (see Create a QS Model).

Note:

> When you set this option and the `enableSearchAsYouType` option to `true`, the query suggestion feature returns the auto-completion of the currently typed keyword as its first query suggestion.

Default

  `true`

Available since

  December 2015 Release (v1.0.273)

Markup configuration example(s) :

    data-enable-query-suggest-addon='true'
    data-enable-query-suggest-addon='false'

### enableQuerySyntax

enableQuerySyntax: boolean

- Defined in ui/Omnibox/Omnibox.ts :238

Specifies whether the Coveo Platform should try to interpret special query syntax such as field references in the query that the user enters in the Querybox (see Coveo Query Syntax Reference).

Setting this option to `true` also causes the query syntax in the Querybox to highlight.

Default value is `false`.

Default

  `false`

Markup configuration example(s) :

    data-enable-query-syntax='true'
    data-enable-query-syntax='false'

### enableSearchAsYouType

enableSearchAsYouType: boolean

- Defined in ui/Omnibox/Omnibox.ts :135

Whether to automatically trigger a new query whenever the end user types additional text in the search box input.

See also the `searchAsYouTypeDelay` option.

Note:

> If you set this option and the `enableQuerySuggestAddon` option to `true`, the query suggestion feature returns the auto-completion of the currently typed keyword as its first suggestion.

Default value is `false`.

Default

  `false`

Markup configuration example(s) :

    data-enable-search-as-you-type='true'
    data-enable-search-as-you-type='false'

### inline

inline: boolean

- Defined in ui/Omnibox/Omnibox.ts :121

Specifies whether query completion suggestions appearing in the `Omnibox` should push the result list and facets down, rather than rendering themselves over them (and partially hiding them).

Set this option as well as Omnibox.options.enableSearchAsYouType and Omnibox.options.enableQuerySuggestAddon to `true` for a cool effect!

Default value is `false`.

Default

  `false`

Markup configuration example(s) :

    data-inline='true'
    data-inline='false'

### numberOfSuggestions

numberOfSuggestions: number

- Defined in ui/Omnibox/Omnibox.ts :253

Specifies the number of suggestions that should appear in standard ML-powered query suggestions.

This option only affects the number of suggestions that appear with the Omnibox.options.enableQuerySuggestAddon option.

This options does not affect the AnalyticsSuggestions or the FieldSuggestions component, which expose their own dedicated options for this parameter.

Default value is `5`.

Minimum value is `1`.

Minimum

  `1`

Default

  `5`

Markup configuration example(s) :

    data-number-of-suggestions='10'

### omniboxTimeout

omniboxTimeout: number

- Defined in ui/Omnibox/Omnibox.ts :228

Specifies a timeout (in milliseconds) before rejecting suggestions in the Omnibox.

Default value is `2000`. Minimum value is `0`.

Minimum

  `0`

Default

  `2000`

Markup configuration example(s) :

    data-omnibox-timeout='10'

### placeholder

placeholder: string

- Defined in ui/Omnibox/Omnibox.ts :221

Specifies a placeholder for the input.

Available since

  July 2016 Release (v1.667.24)

Markup configuration example(s) :

    data-placeholder='foo'

### querySuggestCharacterThreshold

querySuggestCharacterThreshold: number

- Defined in ui/Omnibox/Omnibox.ts :268

The minimum number of characters required in the in the text input before displaying available query suggestions when focus is on the component.

Note: Only effective when enableQuerySuggestAddon is true.

depend: 'enableQuerySuggestAddon'

Default (and minimum): 0, meaning that trending query suggestions are displayed when focus is on the component, even if its text input is empty.

Minimum

  `0`

Default

  `0`

Available since

  July 2019 Release (v2.6459)

Markup configuration example(s) :

    data-query-suggest-character-threshold='10'

### searchAsYouTypeDelay

searchAsYouTypeDelay: number

- Defined in ui/Omnibox/Omnibox.ts :143

If Omnibox.options.enableSearchAsYouType is `true`, specifies the delay (in milliseconds) before triggering a new query when the end user types in the `Omnibox`.

Default value is `2000`. Minimum value is `0`.

Only effective when

  `enableSearchAsYouType` is truthy

Minimum

  `0`

Default

  `2000`

Markup configuration example(s) :

    data-search-as-you-type-delay='10'

## Constructors

### constructor

- new Omnibox(element: HTMLElement, options?: IOmniboxOptions, bindings?: IComponentBindings): Omnibox

- Overwrites Component.constructor

  - Defined in ui/Omnibox/Omnibox.ts :292

  Creates a new Omnibox component. Also enables necessary addons and binds events on various query events.

  #### Parameters

  - ##### element: HTMLElement

    The HTMLElement on which to instantiate the component.

  - ##### Optional options: IOmniboxOptions

    The options for the Omnibox component.

  - ##### Optional bindings: IComponentBindings

    The bindings that the component requires to function normally. If not set, these will be automatically resolved (with a slower execution time).

  #### Returns Omnibox