aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.autocomplete.js
diff options
context:
space:
mode:
authorjzaefferer <joern.zaefferer@gmail.com>2010-04-08 12:05:52 +0200
committerjzaefferer <joern.zaefferer@gmail.com>2010-04-08 12:05:52 +0200
commitc01b3baef97808a3a7dfafaea084c03a27e92564 (patch)
tree1f16a1304e620f012081b6f3f6f49a9107ea8c50 /ui/jquery.ui.autocomplete.js
parent10ea61be5644dc10fa2e11179458ca05b85eb5bc (diff)
downloadjquery-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.js11
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 } );
}
},