diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index fe40ffc1b5..ff1aa07a34 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -415,7 +415,11 @@ var Typeahead = (function() { // cursor moved to different selectable if (data) { - this.input.setInputValue(data.val); + // set the input only if data.val is a string + // don't want to set it to [Object object] + if (typeof data.val === 'string') { + this.input.setInputValue(data.val); + } } // cursor moved off of selectables, back to input diff --git a/test/typeahead/typeahead_spec.js b/test/typeahead/typeahead_spec.js index 6ca80c4b06..a6d75f2a52 100644 --- a/test/typeahead/typeahead_spec.js +++ b/test/typeahead/typeahead_spec.js @@ -16,6 +16,7 @@ describe('Typeahead', function() { this.$input = $fixture.find('input'); testData = { dataset: 'bar', val: 'foo bar', obj: 'fiz' }; + testObjectData = { dataset: 'bar', val: { id: 1, name: 'foo bar' }, obj: { id: 1, name: 'foo bar' } }; this.view = new Typeahead({ input: new Input(), @@ -1383,6 +1384,14 @@ describe('Typeahead', function() { expect(this.input.setInputValue).toHaveBeenCalledWith(testData.val); }); + it('should not update the input value if moved to object selectable', function() { + this.menu.getSelectableData.andReturn(testObjectData); + this.menu.selectableRelativeToCursor.andReturn($()); + + this.view.moveCursor(1); + expect(this.input.setInputValue).not.toHaveBeenCalled(); + }); + it('should reset the input value if moved to input', function() { this.menu.selectableRelativeToCursor.andReturn($()); this.view.moveCursor(1);