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

Commit 6d5b84a

Browse files
icfantvwesleycho
authored andcommitted
fix(typeahead): remove duplicate id attribute
* remove any duplicate `id` attribute on the typeahead hint element if used on the original input element. BREAKING CHANGE: This change removes the `id` attribute on the first `<input>` element placed into the DOM when the `typeahead-show-hint` attribute is used and there is an `id` attribute present on the original `uib-typeahead` element. This could affect selectors if they are being used. Closes #5936 Fixes #5926
1 parent cce0097 commit 6d5b84a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/typeahead/test/typeahead.spec.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ describe('typeahead tests', function() {
222222
expect(element).toBeClosed();
223223
});
224224

225-
226-
227225
it('should support custom model selecting function', function() {
228226
$scope.updaterFn = function(selectedItem) {
229227
return 'prefix' + selectedItem;
@@ -470,6 +468,15 @@ describe('typeahead tests', function() {
470468
};
471469
expect(prepareInvalidDir).toThrow();
472470
});
471+
472+
it('should remove the id attribute from the original DOM element', function() {
473+
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>');
474+
var inputEl = findInput(element);
475+
476+
expect(inputEl.size()).toBe(2);
477+
expect(inputEl.eq(0).attr('id')).toBe(undefined);
478+
expect(inputEl.eq(1).attr('id')).toBe('typeahead-element');
479+
});
473480
});
474481

475482
describe('shouldSelect', function() {

src/typeahead/typeahead.js

+4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.debounce', 'ui.bootstrap
152152
'vertical-align': 'top',
153153
'background-color': 'transparent'
154154
});
155+
156+
if (hintInputElem.attr('id')) {
157+
hintInputElem.removeAttr('id'); // remove duplicate id if present.
158+
}
155159
inputsContainer.append(hintInputElem);
156160
hintInputElem.after(element);
157161
}

0 commit comments

Comments
 (0)