diff --git a/src/typeahead/plugin.js b/src/typeahead/plugin.js index 9c1db197..443c0eb5 100644 --- a/src/typeahead/plugin.js +++ b/src/typeahead/plugin.js @@ -170,7 +170,7 @@ } else { - ttEach(this, function(t) { t.setVal(newVal); }); + ttEach(this, function(t) { t.setVal(_.toStr(newVal)); }); return this; } }, diff --git a/test/typeahead/plugin_spec.js b/test/typeahead/plugin_spec.js index 7399be83..ade34896 100644 --- a/test/typeahead/plugin_spec.js +++ b/test/typeahead/plugin_spec.js @@ -157,6 +157,14 @@ describe('$plugin', function() { expect(this.$input.typeahead('val')).toBe('foo'); }); + it('#val(q) should coerce null and undefined to empty string', function() { + this.$input.typeahead('val', null); + expect(this.$input.typeahead('val')).toBe(''); + + this.$input.typeahead('val', undefined); + expect(this.$input.typeahead('val')).toBe(''); + }); + it('#destroy should revert modified attributes', function() { expect(this.$input).toHaveAttr('autocomplete', 'off'); expect(this.$input).toHaveAttr('dir');