gapi.cloudsearch.widget.searchbox. Builder
Builder of a search box. Use a builder and do not directly call the searchbox constructor.
Constructor
Builder
new Builder()
Example
// Builds a search box.
function onload() {
gapi.client.init({
'apiKey': '<your api key>',
'clientId': '<your client id>',
// Add additional scopes if needed
'scope': 'https://www.googleapis.com/auth/cloud_search.query',
'hosted_domain': '<your G Suite domain>',
});
const searchBox = new gapi.cloudsearch.widget.searchbox.Builder()
.setInput(document.getElementById('input'))
.setAnchor(document.getElementById('input').parentElement)
.build();
}
gapi.load('client:cloudsearch-widget', onload);
Methods
build
build() returns SearchBox
- Returns
-
non-null SearchBox
setAdapter
setAdapter(adapter) returns Builder
Required. Customize the user's search experience with this adapter.
Parameter |
|
---|---|
adapter |
You can override part of the methods. Value must not be null. |
- Returns
-
non-null Builder
this
Example
const adapter = {
interceptSuggestRequest: function(request) {
// Change the request
}
}
builder.setAdapter(adapter).build();
setAnchor
setAnchor(anchor) returns Builder
Required. Must to be a valid HTMLElement that can contain child nodes. Anchor of the search overlay. The overlay is added as the last child in anchor. The position of the overlay is the bottom of anchor.
Parameter |
|
---|---|
anchor |
HTMLElement Value must not be null. |
- Deprecated
- Use `setAnchorElement` instead
- Returns
-
non-null Builder
this
setAnchorElement
setAnchorElement(anchorElement) returns Builder
Required. Must to be a valid HTMLElement that can contain child nodes. Anchor of the search overlay. The overlay is added as the last child in anchor. The position of the overlay is the bottom of anchor.
Parameter |
|
---|---|
anchorElement |
HTMLElement Value must not be null. |
- Returns
-
non-null Builder
this
setHints
setHints(hints) returns Builder
Optional. The hints on the search box when input is empty. When the input is empty, a random hint is picked from the array.
Parameter |
|
---|---|
hints |
Array of string Value must not be null. |
- Returns
-
non-null Builder
this
setInput
setInput(input) returns Builder
Required. An HTMLElement that the user inputs the query. Must be <input> or <textarea>
Parameter |
|
---|---|
input |
HTMLElement Value must not be null. |
- Deprecated
- Use `setInputElement` instead
- Returns
-
non-null Builder
this
setInputElement
setInputElement(inputElement) returns Builder
Required. An HTMLElement that the user inputs the query. Must be <input> or <textarea>
Parameter |
|
---|---|
inputElement |
HTMLElement Value must not be null. |
- Returns
-
non-null Builder
this
setResultsContainer
setResultsContainer(resultsContainer) returns Builder
Optional. Container for displaying search results. If set, the results are rendered in the search results container. If not set, the results are shown in cloudsearch.google.com.
Parameter |
|
---|---|
resultsContainer |
gapi.cloudsearch.widget.resultscontainer.ResultsContainer Value must not be null. |
- See also
- ResultsContainer
- Returns
-
non-null Builder
this
setSearchApplicationId
setSearchApplicationId(searchApplicationId) returns Builder
Optional. Sets the search application ID to use for requests. Must be prefixed with 'searchapplications/'.
Parameter |
|
---|---|
searchApplicationId |
string |
- Returns
-
non-null Builder
this
setThrottleInterval
setThrottleInterval(throttleInterval) returns Builder
Optional. The throttle interval in ms on firing request. The search box sends less than one request every throttleInterval milliseconds. If throttleInternal is less than 200, search box ignores the value and uses 200 as interval instead.
Parameter |
|
---|---|
throttleInterval |
number |
- Returns
-
non-null Builder
this