autocomplete-base.js revision 4e21d9ace0f1e852eddbcea14f5becdce1d8dba9
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Provides automatic input completion or suggestions for text input fields and
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @module autocomplete
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @main autocomplete
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @since 3.3.0
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>Y.Base</code> extension that provides core autocomplete logic (but no
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * UI implementation) for a text input field or textarea. Must be mixed into a
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>Y.Base</code>-derived class to be useful.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @submodule autocomplete-base
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Extension that provides core autocomplete logic (but no UI implementation)
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * for a text input field or textarea.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * The <code>AutoCompleteBase</code> class provides events and attributes that
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * abstract away core autocomplete logic and configuration, but does not provide
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * a widget implementation or suggestion UI. For a prepackaged autocomplete
09ab44e129e6795eed34adfc06f7b741034e88a4Dav Glass * widget, see <code>AutoCompleteList</code>.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * This extension cannot be instantiated directly, since it doesn't provide an
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * actual implementation. It's intended to be mixed into a
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>Y.Base</code>-based class or widget.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>Y.Widget</code>-based example:
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * YUI().use('autocomplete-base', 'widget', function (Y) {
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * var MyAC = Y.Base.create('myAC', Y.Widget, [Y.AutoCompleteBase], {
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * // Custom prototype methods and properties.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * }, {
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * // Custom static methods and properties.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * });
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * // Custom implementation code.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>Y.Base</code>-based example:
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * YUI().use('autocomplete-base', function (Y) {
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * var MyAC = Y.Base.create('myAC', Y.Base, [Y.AutoCompleteBase], {
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * initializer: function () {
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * this._bindUIACBase();
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * this._syncUIACBase();
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * },
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * // Custom prototype methods and properties.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * }, {
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * // Custom static methods and properties.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * });
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * // Custom implementation code.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @class AutoCompleteBase
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren _FUNCTION_VALIDATOR = '_functionValidator',
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren ALLOW_BROWSER_AC = 'allowBrowserAutocomplete',
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren // AOP bindings.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren Y.before(this._bindUIACBase, this, 'bindUI');
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren Y.before(this._destructorACBase, this, 'destructor');
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren Y.before(this._syncUIACBase, this, 'syncUI');
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren // -- Public Events --------------------------------------------------------
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Fires after the query has been completely cleared or no longer meets the
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * minimum query length requirement.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @event clear
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @param {EventFacade} e Event facade with the following additional
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * properties:
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>prevVal (String)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Value of the query before it was cleared.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>src (String)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Source of the event.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @preventable _defClearFn
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Fires when the contents of the input field have changed and the input
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * value meets the criteria necessary to generate an autocomplete query.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @event query
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @param {EventFacade} e Event facade with the following additional
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * properties:
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>inputValue (String)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Full contents of the text input field or textarea that generated
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>query (String)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Autocomplete query. This is the string that will be used to
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * request completion results. It may or may not be the same as
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>inputValue</code>.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>src (String)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Source of the event.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @preventable _defQueryFn
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Fires after query results are received from the <code>source</code>. If
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * no source has been set, this event will not fire.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @event results
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @param {EventFacade} e Event facade with the following additional
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * properties:
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>data (Array|Object)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Raw, unfiltered result data (if available).
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>query (String)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Query that generated these results.
1733ad5823502d24c084b74ae60d838307d23dc0Eduardo Lundgren * <dt>results (Array)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Array of filtered, formatted, and highlighted results. Each item in
d6ed13752962e9de0d6dc030db3f1bcf54e6e540Eduardo Lundgren * the array is an object with the following properties:
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>display (Node|HTMLElement|String)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Formatted result HTML suitable for display to the user. If no
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * custom formatter is set, this will be an HTML-escaped version of
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * the string in the <code>text</code> property.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>highlighted (String)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Highlighted (but not formatted) result text. This property will
6b26605d416d593055b8fba4d274a80efc77a7b3Eduardo Lundgren * only be set if a highlighter is in use.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>raw (mixed)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Raw, unformatted result in whatever form it was provided by the
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>source</code>.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <dt>text (String)</dt>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Plain text version of the result, suitable for being inserted
1733ad5823502d24c084b74ae60d838307d23dc0Eduardo Lundgren * into the value of a text input field or textarea when the result
1733ad5823502d24c084b74ae60d838307d23dc0Eduardo Lundgren * is selected by a user. This value is not HTML-escaped and should
1733ad5823502d24c084b74ae60d838307d23dc0Eduardo Lundgren * not be inserted into the page using innerHTML.
1733ad5823502d24c084b74ae60d838307d23dc0Eduardo Lundgren * @preventable _defResultsFn
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren// -- Public Static Properties -------------------------------------------------
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Whether or not to enable the browser's built-in autocomplete
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * functionality for input fields.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute allowBrowserAutocomplete
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Boolean
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @default false
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * When a <code>queryDelimiter</code> is set, trailing delimiters will
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * automatically be stripped from the input value by default when the
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * input node loses focus. Set this to <code>true</code> to allow trailing
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * delimiters.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute allowTrailingDelimiter
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Boolean
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @default false
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Whether or not to enable in-memory caching in result sources that support
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute enableCache
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Boolean
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @default true
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @since 3.5.0
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren lazyAdd: false, // we need the setter to run on init
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Node to monitor for changes, which will generate <code>query</code>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * events when appropriate. May be either an input field or a textarea.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute inputNode
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Node|HTMLElement|String
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Maximum number of results to return. A value of <code>0</code> or less
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * will allow an unlimited number of results.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute maxResults
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Number
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Minimum number of characters that must be entered before a
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>query</code> event will be fired. A value of <code>0</code>
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * allows empty queries; a negative value will effectively disable all
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>query</code> events.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute minQueryLength
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Number
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Current query, or <code>null</code> if there is no current query.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * The query might not be the same as the current value of the input
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * node, both for timing reasons (due to <code>queryDelay</code>) and
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * because when one or more <code>queryDelimiter</code> separators are
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * in use, only the last portion of the delimited input string will be
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * used as the query value.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute query
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type String|null
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @default null
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Number of milliseconds to delay after input before triggering a
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>query</code> event. If new input occurs before this delay is
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * over, the previous input event will be ignored and a new delay will
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * This can be useful both to throttle queries to a remote data source
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * and to avoid distracting the user by showing them less relevant
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * results before they've paused their typing.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute queryDelay
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Number
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @default 100
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Query delimiter string. When a delimiter is configured, the input value
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * will be split on the delimiter, and only the last portion will be used in
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * autocomplete queries and updated when the <code>query</code> attribute is
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute queryDelimiter
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type String|null
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @default null
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Source request template. This can be a function that accepts a query as a
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * parameter and returns a request string, or it can be a string containing
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * the placeholder "{query}", which will be replaced with the actual
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * URI-encoded query. In either case, the resulting string will be appended
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * to the request URL when the <code>source</code> attribute is set to a
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * remote DataSource, JSONP URL, or XHR URL (it will not be appended to YQL
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * While <code>requestTemplate</code> may be set to either a function or
d6ed13752962e9de0d6dc030db3f1bcf54e6e540Eduardo Lundgren * a string, it will always be returned as a function that accepts a
d6ed13752962e9de0d6dc030db3f1bcf54e6e540Eduardo Lundgren * query argument and returns a string.
d6ed13752962e9de0d6dc030db3f1bcf54e6e540Eduardo Lundgren * @attribute requestTemplate
d6ed13752962e9de0d6dc030db3f1bcf54e6e540Eduardo Lundgren * @type Function|String|null
d6ed13752962e9de0d6dc030db3f1bcf54e6e540Eduardo Lundgren * @default null
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Array of local result filter functions. If provided, each filter
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * will be called with two arguments when results are received: the query
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * and an array of result objects. See the documentation for the
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>results</code> event for a list of the properties available on each
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * result object.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Each filter is expected to return a filtered or modified version of the
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * results array, which will then be passed on to subsequent filters, then
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * the <code>resultHighlighter</code> function (if set), then the
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>resultFormatter</code> function (if set), and finally to
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * subscribers to the <code>results</code> event.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * If no <code>source</code> is set, result filters will not be called.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Prepackaged result filters provided by the autocomplete-filters and
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * autocomplete-filters-accentfold modules can be used by specifying the
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * filter name as a string, such as <code>'phraseMatch'</code> (assuming
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * the necessary filters module is loaded).
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute resultFilters
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Array
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @default []
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Function which will be used to format results. If provided, this function
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * will be called with two arguments after results have been received and
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * filtered: the query and an array of result objects. The formatter is
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * expected to return an array of HTML strings or Node instances containing
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * the desired HTML for each result.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * See the documentation for the <code>results</code> event for a list of
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * the properties available on each result object.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * If no <code>source</code> is set, the formatter will not be called.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute resultFormatter
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Function|null
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Function which will be used to highlight results. If provided, this
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * function will be called with two arguments after results have been
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * received and filtered: the query and an array of filtered result objects.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * The highlighter is expected to return an array of highlighted result
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * text in the form of HTML strings.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * See the documentation for the <code>results</code> event for a list of
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * the properties available on each result object.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * If no <code>source</code> is set, the highlighter will not be called.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute resultHighlighter
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Function|null
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Locator that should be used to extract an array of results from a
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * non-array response.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * By default, no locator is applied, and all responses are assumed to be
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * arrays by default. If all responses are already arrays, you don't need to
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * define a locator.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * The locator may be either a function (which will receive the raw response
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * as an argument and must return an array) or a string representing an
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * object path, such as "foo.bar.baz" (which would return the value of
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * <code>result.foo.bar.baz</code> if the response is an object).
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * While <code>resultListLocator</code> may be set to either a function or a
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * string, it will always be returned as a function that accepts a response
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * argument and returns an array.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute resultListLocator
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Function|String|null
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Current results, or an empty array if there are no results.
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @attribute results
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @type Array
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * @default []
8e7d713a6c785615b5688f96304ae151241dc885Eduardo Lundgren * Locator that should be used to extract a plain text string from a
7e5a8a1727b2daa941a45bbb3d0296d2d5600a9fDav Glass * non-string result item. The resulting text value will typically be the
7e5a8a1727b2daa941a45bbb3d0296d2d5600a9fDav Glass * value that ends up being inserted into an input field or textarea when
* <i>Example:</i> <code>'http://example.com/search?q={query}&callback={callback}'</code>
* <i>Example:</i> <code>'http://example.com/search?q={query}'</code>
source: {
sourceType: {
value: null
tokenInput: {
readOnly: true
value: {
clearCache: function () {
var request,
if (source) {
if (!requestTemplate) {
callback: {
_bindUIACBase: function () {
if (tokenInput) {
if (!inputNode) {
_destructorACBase: function () {
_syncUIACBase: function () {
this._syncBrowserAutocomplete();
var that = this;
var that = this;
var value;
var that = this;
if (!obj) {
return obj;
var facade = {
results: []
results = [],
len,
text,
if (!results) {
if (highlighter) {
if (!highlighted) {
if (formatter) {
if (!formatted) {
if (delim) {
return locator;
var that = this;
return function (result) {
return template;
return function (query) {
if (filters === null) {
return filter;
var acHighlighters;
return highlighter;
return INVALID_VALUE;
|| source === null
return source;
return INVALID_VALUE;
_syncBrowserAutocomplete: function () {
len,
if (delim) {
_afterSourceTypeChange: function (e) {
if (this._rawSource) {
_afterValueChange: function (e) {
self = this,
if (!uiChange) {
if (uiChange) {
fire = function () {
if (delay) {
fire();
_onInputBlur: function (e) {
if (delim) {
_onInputValueChange: function (e) {
_defClearFn: function () {
_defQueryFn: function (e) {
_defResultsFn: function (e) {