diff --git a/doc/jquery.autocomplete.txt b/doc/jquery.autocomplete.txt index bdddd78..6d2bad4 100644 --- a/doc/jquery.autocomplete.txt +++ b/doc/jquery.autocomplete.txt @@ -184,6 +184,13 @@ useDelimiter (default value: false) comma. For example, you may want to allow the user to enter a comma separated list of values--and each value will autocomplete without erasing the other delimited values in the input field. +resultsContainer (default value: null) + HTML element which will contain autocomplete. It will be created and appended to body if not provided. + Contains of this element is replaced with new autocomplete elements each time autocomplete shows up. + +autoPosition (default value: true) + Whether to position container of autocomplete automatically or not. If set to true, it will be aligned + right under input. More advanced options : ======================= diff --git a/src/jquery.autocomplete.js b/src/jquery.autocomplete.js index 02fcdc2..136b94d 100644 --- a/src/jquery.autocomplete.js +++ b/src/jquery.autocomplete.js @@ -80,7 +80,8 @@ useDelimiter: false, delimiterChar: ',', delimiterKeyCode: 188, - processData: null + processData: null, + autoPosition: true }; /** @@ -311,13 +312,20 @@ */ this.dom.$elem.attr('autocomplete', 'off').addClass(this.options.inputClass); - /** - * Create DOM element to hold results, and force absolute position - */ - this.dom.$results = $('
').hide().addClass(this.options.resultsClass).css({ - position: 'absolute' - }); - $('body').append(this.dom.$results); + if (this.options.resultsContainer) { + /** + * Assume that container is already in DOM + */ + this.dom.$results = $(this.options.resultsContainer).hide().addClass(this.options.resultsClass); + } else { + /** + * Create DOM element to hold results, and force absolute position + */ + this.dom.$results = $('
').hide().addClass(this.options.resultsClass).css({ + position: 'absolute' + }); + $('body').append(this.dom.$results); + } /** * Attach keyboard monitoring to $elem @@ -810,9 +818,11 @@ } } - // Always recalculate position before showing since window size or - // input element location may have changed. - this.position(); + if (this.options.autoPosition) { + // Recalculate position before showing since window size or + // input element location may have changed. + this.position(); + } this.dom.$results.html($ul).show(); if (this.options.autoWidth) {