Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable firefox's form auto completion without change events?

So firefox has a nifty mechanism which will try to autocomplete values in fields when a page is reloaded or the back button is used. Which is great and all except when you have something like a drop-down which when set to a value modifies the page using ajax.

What winds up happening is that the browser reloads the page, the drop down is pre-filled with the remembered value, and then no change event is fired when the dom is ready. And therefore the change handlers attached don't fire and thus the page does not update.

Is there a good way to "fix" this behavior so that it works for the user as expected:

a) We do want the browser to auto-complete because that is a good user experience.

b) Still want that onchange event firing.

The only thing I can think of doing at the moment is to add an on-ready event to the document which has javascript pre-populated with initial values in the form, when the document loads the javascript will check the pre-populated values and if not matching what is in the input will trigger the change handlers.

Anyone have a better solution? Is there a lib that does this already?

(Using Rails 2.3.5 + jQuery)

like image 315
Dmitriy Likhten Avatar asked Nov 15 '22 10:11

Dmitriy Likhten


1 Answers

Unfortunately there appears to be no way of actually disabling firefox from auto-filling fields when reloading a page or using the back-forward button. Fortunately the values are already there during $(document).ready() event so as long as everything in those inputs can have the .change even initially fired on them, it don't matter where the values came from and it just works.

like image 150
Dmitriy Likhten Avatar answered Jan 10 '23 06:01

Dmitriy Likhten