Skip to content

Commit 4962715

Browse files
authored
Merge pull request #184 from Gridium/arrow-object-data
on up/down arrow, set the input only if data.val is a string
2 parents 5ad845f + 196fad8 commit 4962715

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/typeahead/typeahead.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,11 @@ var Typeahead = (function() {
416416

417417
// cursor moved to different selectable
418418
if (data) {
419-
this.input.setInputValue(data.val);
419+
// set the input only if data.val is a string
420+
// don't want to set it to [Object object]
421+
if (typeof data.val === 'string') {
422+
this.input.setInputValue(data.val);
423+
}
420424
}
421425

422426
// cursor moved off of selectables, back to input

test/typeahead/typeahead_spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ describe('Typeahead', function() {
1616
this.$input = $fixture.find('input');
1717

1818
testData = { dataset: 'bar', val: 'foo bar', obj: 'fiz' };
19+
testObjectData = { dataset: 'bar', val: { id: 1, name: 'foo bar' }, obj: { id: 1, name: 'foo bar' } };
1920

2021

2122
this.view = new Typeahead({
@@ -1390,6 +1391,14 @@ describe('Typeahead', function() {
13901391
expect(this.input.setInputValue).toHaveBeenCalledWith(testData.val);
13911392
});
13921393

1394+
it('should not update the input value if moved to object selectable', function() {
1395+
this.menu.getSelectableData.andReturn(testObjectData);
1396+
this.menu.selectableRelativeToCursor.andReturn($());
1397+
1398+
this.view.moveCursor(1);
1399+
expect(this.input.setInputValue).not.toHaveBeenCalled();
1400+
});
1401+
13931402
it('should reset the input value if moved to input', function() {
13941403
this.menu.selectableRelativeToCursor.andReturn($());
13951404
this.view.moveCursor(1);

0 commit comments

Comments
 (0)