diff options
author | jzaefferer <joern.zaefferer@gmail.com> | 2010-04-08 12:05:52 +0200 |
---|---|---|
committer | jzaefferer <joern.zaefferer@gmail.com> | 2010-04-08 12:05:52 +0200 |
commit | c01b3baef97808a3a7dfafaea084c03a27e92564 (patch) | |
tree | 1f16a1304e620f012081b6f3f6f49a9107ea8c50 /ui/jquery.ui.autocomplete.js | |
parent | 10ea61be5644dc10fa2e11179458ca05b85eb5bc (diff) | |
download | jquery-ui-c01b3baef97808a3a7dfafaea084c03a27e92564.tar.gz jquery-ui-c01b3baef97808a3a7dfafaea084c03a27e92564.zip |
Autocomplete: Track input changes and fire change-event on blur, along with selected item, if available. Fix for #5490
Diffstat (limited to 'ui/jquery.ui.autocomplete.js')
-rw-r--r-- | ui/jquery.ui.autocomplete.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index a1d798c59..14a19e4b2 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -83,6 +83,7 @@ $.widget( "ui.autocomplete", { } }) .bind( "focus.autocomplete", function() { + self.selectedItem = null; self.previous = self.element.val(); }) .bind( "blur.autocomplete", function( event ) { @@ -91,6 +92,7 @@ $.widget( "ui.autocomplete", { // TODO try to implement this without a timeout, see clearTimeout in search() self.closing = setTimeout(function() { self.close( event ); + self._change( event ); }, 150 ); }); this._initSource(); @@ -116,11 +118,13 @@ $.widget( "ui.autocomplete", { self.element.val( item.value ); } self.close( event ); - self.previous = self.element.val(); // only trigger when focus was lost (click on menu) + var previous = self.previous; if ( self.element[0] !== doc.activeElement ) { self.element.focus(); + self.previous = previous; } + self.selectedItem = item; }, blur: function( event, ui ) { if ( self.menu.element.is(":visible") ) { @@ -219,8 +223,11 @@ $.widget( "ui.autocomplete", { this.menu.element.hide(); this.menu.deactivate(); } + }, + + _change: function( event ) { if ( this.previous !== this.element.val() ) { - this._trigger( "change", event ); + this._trigger( "change", event, { item: this.selectedItem } ); } }, |