0
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-01-28 20:52:21 +01:00

adds minLength #3960

This commit is contained in:
Jacob Thornton 2012-07-22 14:50:52 -07:00
parent 8281a9023a
commit fae6c36874
7 changed files with 42 additions and 7 deletions

View File

@ -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 () {

View File

@ -1690,7 +1690,7 @@
this.query = this.$element.val()
if (!this.query) {
if (!this.query || this.query.length < this.options.minLength) {
return this.shown ? this.hide() : this
}
@ -1888,12 +1888,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 () {

File diff suppressed because one or more lines are too long

View File

@ -1543,6 +1543,12 @@ $('.carousel').carousel({
<td>8</td>
<td>The max number of items to display in the dropdown.</td>
</tr>
<tr>
<td>minLength</td>
<td>number</td>
<td>1</td>
<td>The minimum character length needed before triggering autocomplete suggestions</td>
</tr>
<tr>
<td>matcher</td>
<td>function</td>

View File

@ -1474,6 +1474,12 @@ $('.carousel').carousel({
<td>8</td>
<td>{{_i}}The max number of items to display in the dropdown.{{/i}}</td>
</tr>
<tr>
<td>{{_i}}minLength{{/i}}</td>
<td>{{_i}}number{{/i}}</td>
<td>{{_i}}1{{/i}}</td>
<td>{{_i}}The minimum character length needed before triggering autocomplete suggestions{{/i}}</td>
</tr>
<tr>
<td>{{_i}}matcher{{/i}}</td>
<td>{{_i}}function{{/i}}</td>

View File

@ -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 () {

View File

@ -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()
})
})