Skip to content

Commit 196fad8

Browse files
committed
on up/down arrow, set the input only if data.val is a string
don't want to set it to [Object object] or redo search
1 parent 7c8aa88 commit 196fad8

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
@@ -415,7 +415,11 @@ var Typeahead = (function() {
415415

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

421425
// 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
this.view = new Typeahead({
2122
input: new Input(),
@@ -1383,6 +1384,14 @@ describe('Typeahead', function() {
13831384
expect(this.input.setInputValue).toHaveBeenCalledWith(testData.val);
13841385
});
13851386

1387+
it('should not update the input value if moved to object selectable', function() {
1388+
this.menu.getSelectableData.andReturn(testObjectData);
1389+
this.menu.selectableRelativeToCursor.andReturn($());
1390+
1391+
this.view.moveCursor(1);
1392+
expect(this.input.setInputValue).not.toHaveBeenCalled();
1393+
});
1394+
13861395
it('should reset the input value if moved to input', function() {
13871396
this.menu.selectableRelativeToCursor.andReturn($());
13881397
this.view.moveCursor(1);

0 commit comments

Comments
 (0)