diff options
| author | Jacob Thornton <[email protected]> | 2012-07-22 14:50:52 -0700 |
|---|---|---|
| committer | Jacob Thornton <[email protected]> | 2012-07-22 14:50:52 -0700 |
| commit | fae6c36874b102408b53c6e5d980b247a9779dea (patch) | |
| tree | b9aa63f055d185c9921c8ad6ff16800e2c73f00f /js | |
| parent | 8281a9023a9a687be007de85f1731d131eedaf30 (diff) | |
| download | bootstrap-fae6c36874b102408b53c6e5d980b247a9779dea.tar.xz bootstrap-fae6c36874b102408b53c6e5d980b247a9779dea.zip | |
adds minLength #3960
Diffstat (limited to 'js')
| -rw-r--r-- | js/bootstrap-typeahead.js | 5 | ||||
| -rw-r--r-- | js/tests/unit/bootstrap-typeahead.js | 20 |
2 files changed, 23 insertions, 2 deletions
diff --git a/js/bootstrap-typeahead.js b/js/bootstrap-typeahead.js index 6e896bb98..65b1ddab1 100644 --- a/js/bootstrap-typeahead.js +++ b/js/bootstrap-typeahead.js @@ -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 () { diff --git a/js/tests/unit/bootstrap-typeahead.js b/js/tests/unit/bootstrap-typeahead.js index 25d4cafd8..eb447aaa6 100644 --- a/js/tests/unit/bootstrap-typeahead.js +++ b/js/tests/unit/bootstrap-typeahead.js @@ -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() + }) }) |
