Searchbox
A text input that invokes search requests and integrates with `ff-searchbutton` and `ff-suggest`.
Documentation
Most basic usage:
<ff-searchbox></ff-searchbox>This setup will render a default input element inside and invoke a search request when ENTER is pressed.
By default, it will also send Suggest requests when typing. (In order to display the suggestions, an additional ff-suggest element is required.)
Custom input element
You can define your own input element with required attributes etc., by placing it into the body of ff-searchbox.
<ff-searchbox>
<input placeholder="Search..." />
</ff-searchbox>Linking with ff-searchbutton
In addition to initiating the search by pressing the ENTER key, you can offer clickable buttons with the ff-searchbutton element.
ff-searchbutton relies on the current value in ff-searchbox. As a page may have multiple search boxes and search buttons, each button needs to know which search box's current value it shall use to invoke a search request from. Therefore, it is necessary to link these two elements explicitly. There are two options to establish this link.
By nesting the ff-searchbutton inside an ff-searchbox, the elements automatically detect their relation.
<ff-searchbox>
<input type="search">
<ff-searchbutton><button>Search</button></ff-searchbutton>
</ff-searchbox>Similar to the native HTML elements label and input you can define the id attribute on ff-searchbox and the for attribute on ff-searchbutton and give them the same value. With this approach the elements' locations in the DOM are irrelevant.
<div>
<ff-searchbox id="ffSearchBox">
<input type="search">
</ff-searchbox>
</div>
<div>
<ff-searchbutton for="ffSearchBox">
<button>Search</button>
</ff-searchbutton>
</div>Select input value on click
With the select-onclick attribute you can define whether the current text should be selected when the search box gets focus. (default is "false")
Adding Suggest
By default, ff-searchbox sends a Suggest request every time its text changes and there are at least two characters.
To display the suggestions an ff-suggest element is required. Please see Suggest for information on how to integrate the element.
If you do not wish ff-searchbox to query suggestions, you can turn this behavior off by setting the use-suggest attribute to "false".
Open Suggest on focus
With the property suggest-onfocus set to "true", the Suggest will open whenever the related search box receives focus.
Caching
When you use suggest-onfocus="true", ff-searchbox will cache the last Suggest result and reuse it whenever possible.
It will redispatch the result and the related SuggestParams through Web Components' response pipeline. To pipeline subscribers, such as ff-suggest or your custom handlers, it will appear as if a new Suggest request has been issued.
However, the RequestOptions will be a generic object containing only the origin (the ff-searchbox). See RequestInfoSuggest for data structure.
Adding Popular Searches
To activate the Popular Searches feature you set the popular-searches attribute.
See the Popular Searches article for details.
Demo
API
ff-searchbox
Properties
popular-searches (Boolean)
Setting this attribute activates the Popular Searches feature.
suggest-onfocus (String) Options: "true", "false" (default: "false")
If this property is set to "true", a FactFinder Suggest recommendation is displayed as soon as the search box is in focus.
select-onclick (String) Options: "true", "false" (default: "false")
Determines if the contents of the search box should be selected if the inside of the box is clicked.
use-suggest (String) Options: "true", "false" (default: "true")
Determines if a request should be sent to the suggest interface as soon as a user starts typing a search term.
suggest-delay (Number) (default: 350)
Triggers a suggest request only after the delay expired and no more input is set. When the input field changes within the delay time frame, the delay will reset.
show-asterisk-query (String) Options: "true", "false" (default: "false")
Determines if a single asterisk query ("*") should be displayed in the component's input field. Does not affect value typed in the field by the user.
value (String) (default: empty)
Gets or sets the value of the nested HTML input element. This property is only accessible through JavaScript. Setting value triggers an input event on the input element. Therefore, suggestions whill show if they are enabled.
Methods
search()
Initiates a search with the current search text.
resetInput(selector = 'input')
Tells ff-searchbox which nested element it shall use as its input.
ff-searchbutton
Properties
for (String)
Specify the id of an ff-searchbox element to link the button to that search box.
Methods
resetButton(selector = 'button')
Tells ff-searchbutton which nested element it shall use as its button.
Last updated
Was this helpful?