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

Commit 8126357

Browse files
trueinvisowesleycho
authored andcommittedSep 30, 2015
feat(typeahead): add appendElementToId
- Add appending popup to specific id
1 parent e432059 commit 8126357

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

Diff for: ‎src/typeahead/test/typeahead.spec.js

+10
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,16 @@ describe('typeahead tests', function() {
859859
});
860860
});
861861

862+
describe('append to element id', function() {
863+
it('append typeahead results to element', function() {
864+
$document.find('body').append('<div id="myElement"></div>');
865+
var element = prepareInputEl('<div><input name="input" ng-model="result" typeahead="item for item in states | filter:$viewValue" typeahead-append-to-element-id="myElement"></div>');
866+
changeInputValueTo(element, 'al');
867+
expect($document.find('#myElement')).toBeOpenWithActive(2, 0);
868+
$document.find('#myElement').remove();
869+
});
870+
});
871+
862872
describe('append to body', function() {
863873
it('append typeahead results to body', function() {
864874
var element = prepareInputEl('<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue" typeahead-append-to-body="true"></div>');

Diff for: ‎src/typeahead/typeahead.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
6868

6969
var appendToBody = attrs.typeaheadAppendToBody ? originalScope.$eval(attrs.typeaheadAppendToBody) : false;
7070

71+
var appendToElementId = attrs.typeaheadAppendToElementId || false;
72+
7173
var focusFirst = originalScope.$eval(attrs.typeaheadFocusFirst) !== false;
7274

7375
//If input matches an item of the list exactly, select it automatically
@@ -424,7 +426,7 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
424426

425427
originalScope.$on('$destroy', function() {
426428
$document.unbind('click', dismissClickHandler);
427-
if (appendToBody) {
429+
if (appendToBody || appendToElementId) {
428430
$popup.remove();
429431
}
430432
// Prevent jQuery cache memory leak
@@ -435,6 +437,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position'])
435437

436438
if (appendToBody) {
437439
$document.find('body').append($popup);
440+
} else if (appendToElementId !== false) {
441+
angular.element($document[0].getElementById(appendToElementId)).append($popup);
438442
} else {
439443
element.after($popup);
440444
}

0 commit comments

Comments
 (0)