Support naturalSearch option in typeahead.

The naturalSearch option immediately updates the search box with
the underlying value of a search suggestion when the user moves to
it.

(imported from commit ad5cb5c2591ef4f71a6d648c8839f288cc125cf7)
This commit is contained in:
Steve Howell 2013-07-22 21:01:16 -04:00
parent 49619a85dc
commit dc85fa7cf2
1 changed files with 16 additions and 0 deletions

View File

@ -1826,6 +1826,9 @@
this.source = this.options.source this.source = this.options.source
this.shown = false this.shown = false
this.dropup = this.options.dropup this.dropup = this.options.dropup
// The naturalSearch option causes arrow keys to immediately
// update the search box with the underlying values from the
// search suggestions.
this.listen() this.listen()
} }
@ -1841,6 +1844,11 @@
return this.hide() return this.hide()
} }
, set_value: function () {
var val = this.$menu.find('.active').data('typeahead-value')
this.$element.val(val)
}
, select_and_continue: function () { , select_and_continue: function () {
// We don't call updater() because it potentially has side-effects. // We don't call updater() because it potentially has side-effects.
// This does mean that smartSpaceBar can't be used in cases where the // This does mean that smartSpaceBar can't be used in cases where the
@ -1966,6 +1974,10 @@
} }
next.addClass('active') next.addClass('active')
if (this.options.naturalSearch) {
this.set_value();
}
} }
, prev: function (event) { , prev: function (event) {
@ -1977,6 +1989,10 @@
} }
prev.addClass('active') prev.addClass('active')
if (this.options.naturalSearch) {
this.set_value();
}
} }
, listen: function () { , listen: function () {