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

Commit

Permalink
fix(typeahead): remove duplicate id attribute
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
icfantv authored and wesleycho committed May 29, 2016
1 parent cce0097 commit 6d5b84a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 6d5b84a

Please sign in to comment.