ui.ac.AutoComplete Extends goog.events.EventTarget
This is the central manager class for an AutoComplete instance. The matcher can specify disabled rows that should not be hilited or selected by implementing isRowDisabled(row):boolean for each autocomplete row. No row will be considered disabled if this method is not implemented.

Inheritance

Constructor

goog.ui.ac.AutoComplete(matcherrendererselectionHandler)

Parameters

matcher : Object
A data source and row matcher, implements requestMatchingRows(token, maxMatches, matchCallback).
renderer : goog.events.EventTarget
An object that implements isVisible():boolean.
selectionHandler : Object
An object that implements selectRow(row);.

Instance Methods

Public Protected Private
attachInputWithAnchor(inputElementanchorElement)
Attaches the autocompleter to a text area or text input element with an anchor element. The anchor element is the element the autocomplete box will be positioned against.
Arguments:
inputElement : Element
The input element. May be 'textarea', text 'input' element, or any other element that exposes similar interface.
anchorElement : Element
The anchor element.
code »
attachInputs(var_args)
Attach text areas or input boxes to the autocomplete by DOM reference. After elements are attached to the autocomplete, when a user types they will see the autocomplete drop down.
Arguments:
var_args : ...Element
Variable args: Input or text area elements to attach the autocomplete too.
code »
cancelDelayedDismiss()
Cancel the active delayed dismiss if there is one.
code »
detachInputs(var_args)
Detach text areas or input boxes to the autocomplete by DOM reference.
Arguments:
var_args : ...Element
Variable args: Input or text area elements to detach from the autocomplete.
code »
dismiss()
Clears out the token, rows, and hilite, and calls renderer.dismiss()
code »
dismissOnDelay()
Call a dismiss after a delay, if there's already a dismiss active, ignore.
code »
disposeInternal()
No description.
code »
getAllSuggestions() !Array
No description.
Returns: !Array  The current autocomplete suggestion items.
code »
getHighlightedId() number
No description.
Returns: number  The id (not index!) of the currently highlighted row.
code »
getIdOfIndex_(index) number
Gets the id corresponding to a particular index. (Does no checking.)
Arguments:
index : number
The index of a row in the result set.
Returns: number  The id that currently corresponds to that index.
code »
getIndexOfId(id) number
Gets the index corresponding to a particular id.
Arguments:
id : number
A unique id for the row.
Returns: number  A valid index into rows_, or -1 if the id is invalid.
code »
getMatcher() !Object
No description.
Returns: !Object  The data source providing the `autocomplete suggestions.
code »
getRenderer() goog.events.EventTarget
No description.
Returns: goog.events.EventTarget  The renderer that renders/shows/highlights/hides the autocomplete menu. See constructor documentation for the expected renderer API.
code »
getRowCount() number
Use this.getSuggestionCount(). No description.
Returns: number  Number of rows in the autocomplete.
code »
getSelectionHandler() !Object
No description.
Returns: !Object  The handler used to interact with the input DOM element (textfield, textarea, or richedit), e.g. to update the input DOM element with selected value.
code »
getSuggestion(index) Object
No description.
Arguments:
index : number
The suggestion index, must be within the interval [0, this.getSuggestionCount()).
Returns: Object  The currently suggested item at the given index (or null if there is none).
code »
getSuggestionCount() number
No description.
Returns: number  The number of currently suggested items.
code »
getTarget() Element
Gets the current target HTML node for displaying autocomplete UI.
Returns: Element  The current target HTML node for displaying autocomplete UI.
code »
getToken() ?string
No description.
Returns: ?string  The currently typed token used for completion.
code »
handleEvent(e)
Generic event handler that handles any events this object is listening to.
Arguments:
e : goog.events.Event
Event Object.
code »
hasHighlight() boolean
Returns whether or not the autocomplete is open and has a highlighted row.
Returns: boolean  Whether an autocomplete row is highlighted.
code »
hiliteId(id) boolean
Hilites the id if it's valid and the row is not disabled, otherwise does nothing.
Arguments:
id : number
A row id (not index).
Returns: boolean  Whether the id was hilited. Returns false if the row is disabled.
code »
hiliteIndex(index) boolean
Hilites the index, if it's valid and the row is not disabled, otherwise does nothing.
Arguments:
index : number
The row's index.
Returns: boolean  Whether the index was hilited.
code »
hiliteNext() boolean
Moves the hilite to the next non-disabled row. Calls renderer.hiliteId() when there's something to do.
Returns: boolean  Returns true on a successful hilite.
code »
hilitePrev() boolean
Moves the hilite to the previous non-disabled row. Calls renderer.hiliteId() when there's something to do.
Returns: boolean  Returns true on a successful hilite.
code »
immediatelyCancelDelayedDismiss_() boolean
Cancels any delayed dismiss events immediately.
Returns: boolean  Whether a delayed dismiss was cancelled.
code »
isOpen() boolean
No description.
Returns: boolean  Whether the autocomplete's renderer is open.
code »
matchListener_(matchedTokenrowsopt_options)
Callback passed to Matcher when requesting matches for a token. This might be called synchronously, or asynchronously, or both, for any implementation of a Matcher. If the Matcher calls this back, with the same token this AutoComplete has set currently, then this will package the matching rows in object of the form
{
  id: an integer ID unique to this result set and AutoComplete instance,
  data: the raw row data from Matcher
}
Arguments:
matchedToken : string
Token that corresponds with the rows.
rows : !Array
Set of data that match the given token.
opt_options : (boolean | goog.ui.ac.RenderOptions)=
If true, keeps the currently hilited (by index) element hilited. If false not. Otherwise a RenderOptions object.
code »
renderRows(rowsopt_options)
Renders the rows and adds highlighting.
Arguments:
rows : !Array
Set of data that match the given token.
opt_options : (boolean | goog.ui.ac.RenderOptions)=
If true, keeps the currently hilited (by index) element hilited. If false not. Otherwise a RenderOptions object.
code »
selectHilited() boolean
If there are any current matches, this passes the hilited row data to selectionHandler.selectRow()
Returns: boolean  Whether there are any current matches.
code »
setAllowFreeSelect(allowFreeSelect)
Sets whether or not the up/down arrow can unhilite all rows.
Arguments:
allowFreeSelect : boolean
true iff the up arrow can unhilite all rows.
code »
setAutoHilite(autoHilite)
Sets whether or not the first row should be highlighted by default.
Arguments:
autoHilite : boolean
true iff the first row should be highlighted by default.
code »
setHighlightedIdInternal(id)
Sets the current highlighted row to the given id (not index). Note that this does not change any rendering. NOTE(user): This method will likely go away when we figure out a better API.
Arguments:
id : number
The new highlighted row id.
code »
setMatcher(matcher)
Sets the data source providing the autocomplete suggestions. See constructor documentation for the interface.
Arguments:
matcher : !Object
The matcher.
code »
setMaxMatches(max)
Sets the max number of matches to fetch from the Matcher.
Arguments:
max : number
Max number of matches.
code »
setRenderer(renderer)
Sets the renderer that renders/shows/highlights/hides the autocomplete menu. See constructor documentation for the expected renderer API.
Arguments:
renderer : goog.events.EventTarget
The renderer.
code »
setTarget(target)
Sets the current target HTML node for displaying autocomplete UI. Can be an implementation specific definition of how to display UI in relation to the target node. This target will be passed into renderer.renderRows()
Arguments:
target : Element
The current target HTML node for displaying autocomplete UI.
code »
setToken(tokenopt_fullString)
Sets the token to match against. This triggers calls to the Matcher to fetch the matches (up to maxMatches), and then it triggers a call to renderer.renderRows().
Arguments:
token : string
The string for which to search in the Matcher.
opt_fullString : string=
Optionally, the full string in the input field.
code »
setTokenInternal(token)
Sets the current token (without changing the rendered autocompletion). NOTE(user): This method will likely go away when we figure out a better API.
Arguments:
token : ?string
The new token.
code »
setTriggerSuggestionsOnUpdate(triggerSuggestionsOnUpdate)
Sets whether or not to request new suggestions immediately after completion of a suggestion.
Arguments:
triggerSuggestionsOnUpdate : boolean
true iff completion should fetch new suggestions.
code »
setWrap(wrap)
Sets whether or not selections can wrap around the edges.
Arguments:
wrap : boolean
true iff sections should wrap around the edges.
code »
update(opt_force)
Forces an update of the display.
Arguments:
opt_force : boolean=
Whether to force an update.
code »
addEventListener(typeopt_captureopt_handlerScope)
Use #listen instead, when possible. Otherwise, use goog.events.listen if you are passing Object (instead of Function) as handler. Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched.
Arguments:
type : string
The type of the event to listen for.
: ?function():? | ?{handleEvent:function():?
No description.
opt_capture : boolean=
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope : Object=
Object in whose scope to call the listener.
code »
assertInitialized_()
Asserts that the event target instance is initialized properly.
code »
dispatchEvent()
No description.
code »
disposeInternal()
Removes listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners.
code »
fireListeners()
No description.
code »
getListener()
No description.
code »
getListeners()
No description.
code »
getParentEventTarget() goog.events.EventTarget
Returns the parent of this event target to use for bubbling.
Returns: goog.events.EventTarget  The parent EventTarget or null if there is no parent.
code »
hasListener()
No description.
code »
listen()
No description.
code »
listenOnce()
No description.
code »
removeAllListeners()
No description.
code »
removeEventListener(typeopt_captureopt_handlerScope)
Use #unlisten instead, when possible. Otherwise, use goog.events.unlisten if you are passing Object (instead of Function) as handler. Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.
Arguments:
type : string
The type of the event to listen for.
: ?function():? | ?{handleEvent:function():?
No description.
opt_capture : boolean=
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope : Object=
Object in whose scope to call the listener.
code »
setParentEventTarget(parent)
Sets the parent of this event target to use for capture/bubble mechanism.
Arguments:
parent : goog.events.EventTarget
Parent listenable (null if none).
code »
setTargetForTesting(target)
Sets the target to be used for event.target when firing event. Mainly used for testing. For example, see goog.testing.events.mixinListenable.
Arguments:
target : !Object
The target.
code »
unlisten()
No description.
code »
unlistenByKey()
No description.
code »
addOnDisposeCallback(callbackopt_scope)
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
Arguments:
callback : function(this:T):?
The callback function.
opt_scope : T=
An optional scope to call the callback in.
code »
dispose() void
Disposes of the object. If the object hasn't already been disposed of, calls #disposeInternal. Classes that extend goog.Disposable should override #disposeInternal in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
Returns: void  Nothing.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend goog.Disposable should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' disposeInternal method. Everywhere else the public dispose method must be used. For example:
  mypackage.MyClass = function() {
    mypackage.MyClass.base(this, 'constructor');
    // Constructor logic specific to MyClass.
    ...
  };
  goog.inherits(mypackage.MyClass, goog.Disposable);

  mypackage.MyClass.prototype.disposeInternal = function() {
    // Dispose logic specific to MyClass.
    ...
    // Call superclass's disposeInternal at the end of the subclass's, like
    // in C++, to avoid hard-to-catch issues.
    mypackage.MyClass.base(this, 'disposeInternal');
  };
code »
getDisposed() boolean
Use #isDisposed instead. No description.
Returns: boolean  Whether the object has been disposed of.
code »
isDisposed() boolean
No description.
Returns: boolean  Whether the object has been disposed of.
code »
registerDisposable(disposable)
Associates a disposable object with this object so that they will be disposed together.
Arguments:
disposable : goog.disposable.IDisposable
that will be disposed when this object is disposed.
code »

Instance Properties

allowFreeSelect_ :
True iff the user can unhilight all rows by pressing the up arrow.
Code »
autoHilite_ :
True iff the first row should automatically be highlighted
Code »
constructor :
No description.
Code »
dismissTimer_ :
The timer id for dismissing autocomplete menu with a delay.
Code »
firstRowId_ :
Id of the first row in autocomplete menu. Note that new ids are assigned everytime new suggestions are fetched. TODO(user): Figure out what subclass does with this value and whether we should expose a more proper API.
Code »
hiliteId_ :
Id of the currently highlighted row.
Code »
inputToAnchorMap_ :
Mapping from text input element to the anchor element. If the mapping does not exist, the input element will act as the anchor element.
Code »
matcher_ :
A data-source which provides autocomplete suggestions. TODO(user): Tighten the type to !goog.ui.ac.AutoComplete.Matcher.
Code »
maxMatches_ :
The maximum number of matches that should be returned
Code »
A renderer to render/show/highlight/hide the autocomplete menu.
Code »
rows_ :
Autocomplete suggestion items.
Code »
selectionHandler_ :
A handler which interacts with the input DOM element (textfield, textarea, or richedit). TODO(user): Tighten the type to !Object.
Code »
target_ :
The target HTML node for displaying.
Code »
token_ :
Currently typed token which will be used for completion.
Code »
triggerSuggestionsOnUpdate_ :
Whether completion from suggestion triggers fetching new suggestion.
Code »
wrap_ :
True iff item selection should wrap around from last to first. If allowFreeSelect_ is on in conjunction, there is a step of free selection before wrapping.
Code »
actualEventTarget_ : goog.events.EventTarget
The object to use for event.target. Useful when mixing in an EventTarget to another object.
Code »
constructor :
No description.
Code »
eventTargetListeners_ : goog.events.ListenerMap
Maps of event type to an array of listeners.
Code »
parentEventTarget_ : goog.events.EventTarget
Parent event target, used during event bubbling. TODO(user): Change this to goog.events.Listenable. This currently breaks people who expect getParentEventTarget to return goog.events.EventTarget.
Code »
creationStack :
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
Code »
disposed_ :
Whether the object has been disposed of.
Code »
onDisposeCallbacks_ :
Callbacks to invoke when this object is disposed.
Code »

Static Properties

goog.ui.ac.AutoComplete.Matcher :
No description.
Code »
goog.ui.ac.AutoComplete.superClass_ :
No description.
Code »

Enumerations

goog.ui.ac.AutoComplete.EventType :
Events associated with the autocomplete
Constants:
CANCEL_DISMISS
No description.
DISMISS
No description.
HILITE
No description.
ROW_HILITE
No description.
SELECT
No description.
SUGGESTIONS_UPDATE
No description.
UPDATE
No description.
Code »

Package ui.ac

Package Reference