Gravatar for

Question by Noel Brennan, Jan 18, 2019 11:55 AM

We are using a custom fieldSuggestion, but the enter key doesn't work

In the custom fieldSuggestion when we use the up and down keys to scroll the autosuggested results and then hit the enter key on a suggestion nothing happens. Is there a way to easily implement this feature?

Gravatar for

Comment by Jean-François L'Heureux, Jan 18, 2019 1:31 PM

To answer your question, we need more information:

  • What do you mean by "custom fieldSuggestion"? Is it the standard `CoveoFieldSuggestion` JS UI component?
  • Which product are you using Coveo for Sitecore, Coveo for Salesforce, Coveo for Microsoft Dynamics 365, Coveo for ServiceNow?
  • Which version of that product do you use (including the build number)?
  • Which version of the JS UI do you use? Type `Coveo.version` in your browser developer tools console.
Gravatar for

Comment by Noel Brennan, Jan 18, 2019 4:34 PM

The Coveo response says apiversion: 2. Its a custom "type script" .ts file customproductsuggestionsts.txt that we convert to javascript and we use it like this in our UI.

<div className="CoveoSearchbox" data-enable-omnibox="true" data-enable-field-addon="true" data-number-of-suggestions="3" data-placeholder={placeHolder} >
  <div id="suggestedProducts" className="CoveoCustomProductSuggestions" data-query-override='@source=="km-product"' data-header-title="Suggested Products" data-number-of-suggestions={productCount} data-omnibox-z-index='100'></div>
1 Reply
Gravatar for

Answer by Jean-François L'Heureux, Jan 18, 2019 5:59 PM

You implemented a fully custom suggestion provider. I see it has an `onSelect` option that returns `null`. I also see you only attached a `click` event handler on the suggestion elements that calls the `handleSuggestionClick` function that seems to be responsible for redirecting the user to another location. Since it is your own code, you have to debug it yourself. It has nothing to do with Coveo.

If I was to guess, I would look at the `onSelect` option. It might be called by the JS UI when hitting the Enter key. You might want to remove your own `onClick` handler on the suggestion elements and only use the `onSelect` option to handle selection.

Gravatar for

Comment by Noel Brennan, Jan 22, 2019 4:26 PM

@jpdery Thanks for the answer JP -> The keyboardSelect event is what is triggered by the Omnibox when a user selects your element by hitting enter on his keyboard. See:

Coveo.$(el).on('keyboardSelect', () => { 
CustomProductSuggestions.handleSuggestionClick(inst, result)
Ask a question