Skip to content

Commit e2d9608

Browse files
committed
Merge pull request #1199 from jharding/1163-val-undefined
Coerce val to string when set through API
2 parents b2b588d + c58519e commit e2d9608

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/typeahead/plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
}
171171

172172
else {
173-
ttEach(this, function(t) { t.setVal(newVal); });
173+
ttEach(this, function(t) { t.setVal(_.toStr(newVal)); });
174174
return this;
175175
}
176176
},

test/typeahead/plugin_spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ describe('$plugin', function() {
157157
expect(this.$input.typeahead('val')).toBe('foo');
158158
});
159159

160+
it('#val(q) should coerce null and undefined to empty string', function() {
161+
this.$input.typeahead('val', null);
162+
expect(this.$input.typeahead('val')).toBe('');
163+
164+
this.$input.typeahead('val', undefined);
165+
expect(this.$input.typeahead('val')).toBe('');
166+
});
167+
160168
it('#destroy should revert modified attributes', function() {
161169
expect(this.$input).toHaveAttr('autocomplete', 'off');
162170
expect(this.$input).toHaveAttr('dir');

0 commit comments

Comments
 (0)