Commit fae6c368 authored by Jacob Thornton's avatar Jacob Thornton

adds minLength #3960

parent 8281a902
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
this.query = this.$element.val() this.query = this.$element.val()
if (!this.query) { if (!this.query || this.query.length < this.options.minLength) {
return this.shown ? this.hide() : this return this.shown ? this.hide() : this
} }
...@@ -279,12 +279,13 @@ ...@@ -279,12 +279,13 @@
, items: 8 , items: 8
, menu: '<ul class="typeahead dropdown-menu"></ul>' , menu: '<ul class="typeahead dropdown-menu"></ul>'
, item: '<li><a href="#"></a></li>' , item: '<li><a href="#"></a></li>'
, minLength: 1
} }
$.fn.typeahead.Constructor = Typeahead $.fn.typeahead.Constructor = Typeahead
/* TYPEAHEAD DATA-API /* TYPEAHEAD DATA-API
* ================== */ * ================== */
$(function () { $(function () {
......
...@@ -1690,7 +1690,7 @@ ...@@ -1690,7 +1690,7 @@
this.query = this.$element.val() this.query = this.$element.val()
if (!this.query) { if (!this.query || this.query.length < this.options.minLength) {
return this.shown ? this.hide() : this return this.shown ? this.hide() : this
} }
...@@ -1888,12 +1888,13 @@ ...@@ -1888,12 +1888,13 @@
, items: 8 , items: 8
, menu: '<ul class="typeahead dropdown-menu"></ul>' , menu: '<ul class="typeahead dropdown-menu"></ul>'
, item: '<li><a href="#"></a></li>' , item: '<li><a href="#"></a></li>'
, minLength: 1
} }
$.fn.typeahead.Constructor = Typeahead $.fn.typeahead.Constructor = Typeahead
/* TYPEAHEAD DATA-API /* TYPEAHEAD DATA-API
* ================== */ * ================== */
$(function () { $(function () {
......
This diff is collapsed.
...@@ -1543,6 +1543,12 @@ $('.carousel').carousel({ ...@@ -1543,6 +1543,12 @@ $('.carousel').carousel({
<td>8</td> <td>8</td>
<td>The max number of items to display in the dropdown.</td> <td>The max number of items to display in the dropdown.</td>
</tr> </tr>
<tr>
<td>minLength</td>
<td>number</td>
<td>1</td>
<td>The minimum character length needed before triggering autocomplete suggestions</td>
</tr>
<tr> <tr>
<td>matcher</td> <td>matcher</td>
<td>function</td> <td>function</td>
......
...@@ -1474,6 +1474,12 @@ $('.carousel').carousel({ ...@@ -1474,6 +1474,12 @@ $('.carousel').carousel({
<td>8</td> <td>8</td>
<td>{{_i}}The max number of items to display in the dropdown.{{/i}}</td> <td>{{_i}}The max number of items to display in the dropdown.{{/i}}</td>
</tr> </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> <tr>
<td>{{_i}}matcher{{/i}}</td> <td>{{_i}}matcher{{/i}}</td>
<td>{{_i}}function{{/i}}</td> <td>{{_i}}function{{/i}}</td>
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
this.query = this.$element.val() this.query = this.$element.val()
if (!this.query) { if (!this.query || this.query.length < this.options.minLength) {
return this.shown ? this.hide() : this return this.shown ? this.hide() : this
} }
...@@ -279,12 +279,13 @@ ...@@ -279,12 +279,13 @@
, items: 8 , items: 8
, menu: '<ul class="typeahead dropdown-menu"></ul>' , menu: '<ul class="typeahead dropdown-menu"></ul>'
, item: '<li><a href="#"></a></li>' , item: '<li><a href="#"></a></li>'
, minLength: 1
} }
$.fn.typeahead.Constructor = Typeahead $.fn.typeahead.Constructor = Typeahead
/* TYPEAHEAD DATA-API /* TYPEAHEAD DATA-API
* ================== */ * ================== */
$(function () { $(function () {
......
...@@ -181,4 +181,24 @@ $(function () { ...@@ -181,4 +181,24 @@ $(function () {
typeahead.$menu.remove() 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()
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment