mirror of
https://github.com/twbs/bootstrap.git
synced 2025-08-12 08:34:08 +02:00
adds minLength #3960
This commit is contained in:
5
js/bootstrap-typeahead.js
vendored
5
js/bootstrap-typeahead.js
vendored
@@ -81,7 +81,7 @@
|
||||
|
||||
this.query = this.$element.val()
|
||||
|
||||
if (!this.query) {
|
||||
if (!this.query || this.query.length < this.options.minLength) {
|
||||
return this.shown ? this.hide() : this
|
||||
}
|
||||
|
||||
@@ -279,12 +279,13 @@
|
||||
, items: 8
|
||||
, menu: '<ul class="typeahead dropdown-menu"></ul>'
|
||||
, item: '<li><a href="#"></a></li>'
|
||||
, minLength: 1
|
||||
}
|
||||
|
||||
$.fn.typeahead.Constructor = Typeahead
|
||||
|
||||
|
||||
/* TYPEAHEAD DATA-API
|
||||
/* TYPEAHEAD DATA-API
|
||||
* ================== */
|
||||
|
||||
$(function () {
|
||||
|
20
js/tests/unit/bootstrap-typeahead.js
vendored
20
js/tests/unit/bootstrap-typeahead.js
vendored
@@ -181,4 +181,24 @@ $(function () {
|
||||
|
||||
typeahead.$menu.remove()
|
||||
})
|
||||
|
||||
test("should start querying when minLength is met", function () {
|
||||
var $input = $('<input />').typeahead({
|
||||
source: ['aaaa', 'aaab', 'aaac'],
|
||||
minLength: 3
|
||||
})
|
||||
, typeahead = $input.data('typeahead')
|
||||
|
||||
$input.val('aa')
|
||||
typeahead.lookup()
|
||||
|
||||
equals(typeahead.$menu.find('li').length, 0, 'has 0 items in menu')
|
||||
|
||||
$input.val('aaa')
|
||||
typeahead.lookup()
|
||||
|
||||
equals(typeahead.$menu.find('li').length, 3, 'has 3 items in menu')
|
||||
|
||||
typeahead.$menu.remove()
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user