Class: UWA.Controls.AutocompleteAdaptors.Abstract

UWA/Controls/AutocompleteAdaptors/Abstract. UWA.Controls.AutocompleteAdaptors.Abstract

<virtual> new UWA.Controls.AutocompleteAdaptors.Abstract(options)

Parameters
Name Type Argument Description
options Object <optional>

Options hash or a option/value pair.

Mixes In

  • UWA.Class.Options

Index

Methods

getSuggestions(text, caret) → {Promise}

Get suggestions for a given text and the caret position. Should be overriden.

Suggestion objects should either be "full" or "inline".

Full suggestions are replacing a portion of the current input value with another value. They contain the properties fullValue, start and end, offsets of the portion to replace.

Inline suggestions are appended to the right of the caret inside the input value. They don't replace any portion of the current value: they only complete it. They contain the property inlineValue

Other properties are passed to the renderSuggestion method. The default renderSuggestion uses the displayValue property to print the value to the user.

Example
var words = [ "foo", "bar" ];

var FullAdaptor = AbstractAdaptor.extend({

    getSuggestions: function (text, caret) {
        var start = text.slice(0, caret);
        var lastWord = /\w*$/.exec(start)[0];
        var re = new RegExp('^' + UWAString.escapeRegExp(lastWord), 'i');
        if (lastWord.length) {
            return words.filter(function (w) {
                return re.test(w) && w !== lastWord;
            }).map(function (word) {
                return {
                    displayValue: word,
                    start: caret - lastWord.length,
                    end: caret,
                    fullValue: word
                };
            }, this);
        }

        return [];
    }
});

var InlineAdaptor = AbstractAdaptor.extend({

    getSuggestions: function (text, caret) {
        var start = text.slice(0, caret);
        var lastWord = /\w*$/.exec(start)[0];
        var re = new RegExp('^' + UWAString.escapeRegExp(lastWord), 'i');
        if (lastWord.length) {
            return words.filter(function (w) {
                return re.test(w) && w !== lastWord;
            }).map(function (word) {
                return {
                    inlineValue: word.slice(lastWord.length),
                    displayValue: word
                };
            }, this);
        }

        return [];
    }
});
Parameters
Name Type Description
text String

the current input text

caret Number

the caret offset inside the text

Returns

resolved with an array of suggestion objects

Type
Promise

renderSuggestions(suggestions) → {Any}

Render a list of suggestion objects. This will be used to populate the suggestion dropdown.

Parameters
Name Type Description
suggestions Array
Returns

anything supported by Element.setContent

Type
Any

renderSuggestion(suggestion) → {Any}

Render a single suggestion object.

Parameters
Name Type Description
suggestion Object
Returns

anything supported by Element.setContent

Type
Any