Skip to content

Commit b41873b

Browse files
committed
Autocomplete: Re-enable native autocomplete whent he page is unloaded. Fixes #7790 - Autocomplete-enabled text input does not keep value when using back button in browser.
1 parent 1e2fcb9 commit b41873b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ui/jquery.ui.autocomplete.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ $.widget( "ui.autocomplete", {
215215
if ( $.fn.bgiframe ) {
216216
this.menu.element.bgiframe();
217217
}
218+
// turning off autocomplete prevents the browser from remembering the
219+
// value when navigating through history, so we re-enable autocomplete
220+
// if the page is unloaded before the widget is destroyed. #7790
221+
self.beforeunloadHandler = function() {
222+
self.element.removeAttr( "autocomplete" );
223+
};
224+
$( window ).bind( "beforeunload", self.beforeunloadHandler );
218225
},
219226

220227
destroy: function() {
@@ -225,6 +232,7 @@ $.widget( "ui.autocomplete", {
225232
.removeAttr( "aria-autocomplete" )
226233
.removeAttr( "aria-haspopup" );
227234
this.menu.element.remove();
235+
$( window ).unbind( "beforeunload", this.beforeunloadHandler );
228236
$.Widget.prototype.destroy.call( this );
229237
},
230238

0 commit comments

Comments
 (0)