From 0f3d6f87bcde02698b5f744603040c50b2efd8e2 Mon Sep 17 00:00:00 2001 From: Adam Gordon Date: Sat, 28 May 2016 15:52:06 -0600 Subject: [PATCH] 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 `` 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. Fixes #5926 --- src/typeahead/test/typeahead.spec.js | 11 +++++++++-- src/typeahead/typeahead.js | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/typeahead/test/typeahead.spec.js b/src/typeahead/test/typeahead.spec.js index a06de20044..4b5b44691a 100644 --- a/src/typeahead/test/typeahead.spec.js +++ b/src/typeahead/test/typeahead.spec.js @@ -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; @@ -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('
'); + 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() { diff --git a/src/typeahead/typeahead.js b/src/typeahead/typeahead.js index db33f5043e..1e9c7245f3 100644 --- a/src/typeahead/typeahead.js +++ b/src/typeahead/typeahead.js @@ -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); }