<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,startandend, 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
inlineValueOther properties are passed to the
renderSuggestionmethod. The default renderSuggestion uses thedisplayValueproperty 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 textString the current input text
caretNumber 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 suggestionsArray Returns
anything supported by Element.setContent
- Type
- Any
-
renderSuggestion(suggestion) → {Any}
-
Render a single suggestion object.
Parameters
Name Type Description suggestionObject Returns
anything supported by Element.setContent
- Type
- Any