Support smartSpaceBar option in typeahead.

If you set the option, then hitting space will select the current
suggestion and allow you to keep typing.  If you don't set it,
then it's the old behavior where space allows you to continue
typing without acknowledging your selection.

(imported from commit 8125a322e5a748ac7716361d66fca18c56d5766e)
This commit is contained in:
Steve Howell 2013-07-17 18:44:28 -04:00
parent cd71840942
commit fcb3999996
1 changed files with 23 additions and 0 deletions

View File

@ -1841,6 +1841,19 @@
return this.hide()
}
, select_and_continue: function () {
// We don't call updater() because it potentially has side-effects.
// This does mean that smartSpaceBar can't be used in cases where the
// item values are transformed by updater(). It's generally imprudent
// to do transformations in updater(), so this should be a
// non-issue for most users.
var val = this.$menu.find('.active').data('typeahead-value')
this.$element
.val(val + ' ')
.change()
return this.hide()
}
, updater: function (item) {
return item
}
@ -2027,6 +2040,16 @@
this.select()
break
case 32: // space
if (this.options.smartSpaceBar) {
if (!this.shown) return
this.select_and_continue()
}
else {
this.lookup()
}
break
case 27: // escape
if (!this.shown) return
this.hide()