# Coveo FieldSuggestions Component (CoveoFieldSuggestions)

The `FieldSuggestions` component provides query suggestions based on a particular facet field. For example, you could use this component to provide auto-complete suggestions while the end user is typing the title of an item.

The query suggestions provided by this component appear in the `Omnibox` component.

Note: Consider providing Coveo ML query suggestions rather than field suggestions, as the former yields better performance and relevance.

## Index

### Methods

- debugInfo
- disable
- enable
- getBindings
- selectSuggestion
- get

### Properties

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

### Accessors

- usageAnalytics

### Component Options

- field
- headerTitle
- numberOfSuggestions
- omniboxZIndex
- onSelect
- queryOverride

### Constructors

- constructor

## Methods

### 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

### selectSuggestion

- selectSuggestion(suggestion: any): void

- - Defined in ui/FieldSuggestions/FieldSuggestions.ts :243

  Selects a currently displayed query suggestion. This implies that at least one suggestion must have been returned at least once.

  #### Parameters

  - ##### suggestion: any

    Either a number (0-based index position of the query suggestion to select) or a string that matches the suggestion to select.

  #### 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

### field

field: IFieldOption

- Defined in ui/FieldSuggestions/FieldSuggestions.ts :57

Specifies the facet field from which to provide suggestions.

Specifying a value for this option is required for the `FieldSuggestions` component to work.

Required

  Specifying a value for this option is required for the component to work

Markup configuration example(s) :

    data-field='@foo'

### headerTitle

headerTitle: string

- Defined in ui/FieldSuggestions/FieldSuggestions.ts :83

Specifies the title of the result suggestions group in the `Omnibox` component. If not provided, the component will simply not output any title.

Default value is `null`.

Markup configuration example(s) :

    data-header-title='foo'

### numberOfSuggestions

numberOfSuggestions: number

- Defined in ui/FieldSuggestions/FieldSuggestions.ts :90

Specifies the number of suggestions to render in the `Omnibox`.

Default value is `5`. Minimum value is `1`.

Minimum

  `1`

Default

  `5`

Markup configuration example(s) :

    data-number-of-suggestions='10'

### omniboxZIndex

omniboxZIndex: number

- Defined in ui/FieldSuggestions/FieldSuggestions.ts :75

Specifies the z-index position at which the suggestions render themselves in the `Omnibox`.

When there are multiple suggestion providers, components with higher `omniboxZIndex` values render themselves first.

Default value is `51`. Minimum value is `0`.

Minimum

  `0`

Default

  `51`

Markup configuration example(s) :

    data-omnibox-z-index='10'

### onSelect

onSelect: ISuggestionForOmniboxOptionsOnSelect

- Defined in ui/FieldSuggestions/FieldSuggestions.ts :149

Specifies the event handler function to execute when the end user selects a suggested value in the `Omnibox`. By default, the query box text is replaced by what the end user selected and a new query is executed. You can, however, replace this default behavior by providing a callback function to execute when the value is selected.

Note:

> You cannot set this option directly in the component markup as an HTML attribute. You must either set it in the `init` call of your search interface (see Passing Component Options in the init Call), or before the `init` call, using the `options` top-level function (see Passing Component Options Before the init Call).

Example:

    var myOnSelectFunction = function(selectedValue, populateOmniboxEventArgs) {

      // Close the suggestion list when the user clicks a suggestion.
      populateOmniboxEventArgs.closeOmnibox();

      // Search for matching title results in the default endpoint.
      Coveo.SearchEndpoint.endpoints["default"].search({
        q: "@title==" + selectedValue
      }).done(function(results) {

        // If more than one result is found, select a result that matches the selected title.
        var foundResult = Coveo._.find(results.results, function(result) {
          return selectedValue == result.raw.title;
        });

        // Open the found result in the current window, or log an error.
        if (foundResult) {
          window.location = foundResult.clickUri;
        }
        else {
          new Coveo.Logger.warn("Selected suggested result '" + selectedValue + "' not found.");
        }
      });
    };

    // You can set the option in the 'init' call:
    Coveo.init(document.querySelector("#search"), {
       FieldSuggestions : {
         onSelect : myOnSelectFunction
       }
    });

    // Or before the 'init' call, using the 'options' top-level function:
    // Coveo.options(document.querySelector("#search"), {
    //   FieldSuggestions : {
    //     onSelect : myOnSelectFunction
    //   }
    // });

### queryOverride

queryOverride: string

- Defined in ui/FieldSuggestions/FieldSuggestions.ts :65

Specifies a query override to apply when retrieving suggestions. You can use any valid query expression (see Coveo Query Syntax Reference).

Default value is the empty string, and the component applies no query override.

Default

  ``

Markup configuration example(s) :

    data-query-override='foo'

## Constructors

### constructor

- new FieldSuggestions(element: HTMLElement, options: IFieldSuggestionsOptions, bindings?: IComponentBindings): FieldSuggestions

- Overwrites Component.constructor

  - Defined in ui/FieldSuggestions/FieldSuggestions.ts :155

  Creates a new `FieldSuggestions` component.

  #### Parameters

  - ##### element: HTMLElement

    The HTMLElement on which to instantiate the component.

  - ##### options: IFieldSuggestionsOptions

    The options for the `FieldSuggestions` 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 FieldSuggestions