No events or hooks or option allows selected suggestion to be appended to the current input, instead of being replaced.
You can implement your own workaround with the existing typeahead functionality if you use the displayKey and templates properties in your dataset. 'displayKey' will dictate what actual text gets set in the input widget after you select a suggestion. The 'templates' property lets you set a suggestion template function to control what gets displayed.
For example:
typeahead.typeahead({
highlight: true,
}, {
name: 'example',
displayKey: 'output',
source: suggester,
templates: {
suggestion: function (i) {
return '<p>' + i.value + '</p>'
}
}
});
suggester is your source callback that should generate suggestions with both an output field and a value field. You'd set output to be the concatenated string of the previous value (the query argument passed to the source callback) plus the suggestion. Your value field would just be the suggestion for abbreviated display. For example:
var suggester = function(query, syncResults) {
var results = {value: i, query: query + i};
syncResults(results);
}
If you'd like to do a partial term replacement rather than just a straight up append, you'll need to do some combination of tokenization/parsing/string manipulation to manage replacing just that trailing partial word.
Most helpful comment
You can implement your own workaround with the existing typeahead functionality if you use the
displayKeyandtemplatesproperties in your dataset. 'displayKey' will dictate what actual text gets set in the input widget after you select a suggestion. The 'templates' property lets you set asuggestiontemplate function to control what gets displayed.For example:
suggesteris your source callback that should generate suggestions with both anoutputfield and avaluefield. You'd setoutputto be the concatenated string of the previous value (thequeryargument passed to the source callback) plus the suggestion. Yourvaluefield would just be the suggestion for abbreviated display. For example:If you'd like to do a partial term replacement rather than just a straight up append, you'll need to do some combination of tokenization/parsing/string manipulation to manage replacing just that trailing partial word.