Class: Builder

Constructor

Builder

new Builder()

Example

// Builds a search box.
function onload() {
  gapi.client.init({
    'apiKey': '',
    'clientId': '',
    // Add additional scopes if needed
    'scope': 'https://www.googleapis.com/auth/cloud_search.query',
    'hosted_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

SearchBoxAdapter

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 or