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

Typeahead append element to div with id #4231

Closed
wants to merge 2 commits 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
8 changes: 8 additions & 0 deletions src/typeahead/test/typeahead.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,14 @@ describe('typeahead tests', function() {
});
});

describe('append to element id', function() {
it('append typeahead results to element', function() {
var element = prepareInputEl('<div><div id="myElement"></div><input name="input" ng-model="result" typeahead="item for item in states | filter:$viewValue" typeahead-append-to-element-id="myElement"></div>');
changeInputValueTo(element, 'ba');
expect($document.find('#myElement')).toBeOpenWithActive(2, 0);
});
});

describe('append to body', function() {
it('append typeahead results to body', function() {
var element = prepareInputEl('<div><input ng-model="result" typeahead="item for item in source | filter:$viewValue" typeahead-append-to-body="true"></div>');
Expand Down
4 changes: 4 additions & 0 deletions src/typeahead/typeahead.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap

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

var appendToElementId = attrs.typeaheadAppendToElementId || false;

var focusFirst = originalScope.$eval(attrs.typeaheadFocusFirst) !== false;

//If input matches an item of the list exactly, select it automatically
Expand Down Expand Up @@ -419,6 +421,8 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap

if (appendToBody) {
$document.find('body').append($popup);
} else if(appendToElementId !== false) {
$document.find('#' + appendToElementId).append($popup);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be noted that this library does not have a dependency on jQuery, so this would fail with purely jqLite.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One workaround here is to do $document[0].getElementById(appendToElementId)

} else {
element.after($popup);
}
Expand Down