🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/typeahead/typeahead_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
Expand Down