Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

fix(typeahead): remove duplicate id attribute #5936

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 9 additions & 2 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,6 @@ describe('typeahead tests', function() {
expect(element).toBeClosed();
});



it('should support custom model selecting function', function() {
$scope.updaterFn = function(selectedItem) {
return 'prefix' + selectedItem;
Expand Down Expand Up @@ -470,6 +468,15 @@ describe('typeahead tests', function() {
};
expect(prepareInvalidDir).toThrow();
});

it('should remove the id attribute from the original DOM element', function() {
var element = prepareInputEl('<div><input id="typeahead-element" ng-model="result" uib-typeahead="item for item in source | filter:$viewValue" typeahead-show-hint="true"></div>');
var inputEl = findInput(element);

expect(inputEl.size()).toBe(2);
expect(inputEl.eq(0).attr('id')).toBe(undefined);
expect(inputEl.eq(1).attr('id')).toBe('typeahead-element');
});
});

describe('shouldSelect', function() {
Expand Down
4 changes: 4 additions & 0 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
'vertical-align': 'top',
'background-color': 'transparent'
});

if (hintInputElem.attr('id')) {
hintInputElem.removeAttr('id'); // remove duplicate id if present.
}
inputsContainer.append(hintInputElem);
hintInputElem.after(element);
}
Expand Down