typeahead: Support custom selection triggers in bootstrap typeahead.

We add support for triggering typeahead_completion on custom keyup events
in addition to Tab and Enter. The function `this.trigger_selection` takes
the keyup event as its argument and has the same `this` context as the other
typeahead functions.

This is being added to support partial completion of stream typeahead to
directly start the topic_list typeahead.
This commit is contained in:
Rohitt Vashishtha
2019-07-18 12:16:10 +00:00
committed by Tim Abbott
parent 63e200997d
commit 83cbd62ba1

View File

@@ -28,6 +28,17 @@
* choice.
*
* Our custom changes include all mentions of this.automated.
*
* 2. Custom selection triggers:
*
* This adds support for completing a typeahead on custom keyup input. By
* default, we only support Tab and Enter to complete a typeahead, but we
* have usecases where we want to complete using custom characters like: >.
*
* If `this.trigger_selection` returns true, we complete the typeahead and
* pass the keyup event to the updater.
*
* Our custom changes include all mentions of this.trigger_selection.
* ============================================================ */
!function($){
@@ -51,6 +62,7 @@
this.dropup = this.options.dropup
this.fixed = this.options.fixed || false;
this.automated = this.options.automated || this.automated;
this.trigger_selection = this.options.trigger_selection || this.trigger_selection;
if (this.fixed) {
this.$menu.css('position', 'fixed');
@@ -86,6 +98,10 @@
return false;
}
, trigger_selection: function() {
return false;
}
, show: function () {
var pos;
@@ -310,6 +326,10 @@
break
default:
if (this.trigger_selection(e)) {
if (!this.shown) return;
this.select(e);
}
this.lookup()
}