views:

86

answers:

2

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)

A: 

I think you can add autocomplete="off" to prevent the browser from prefilling those fields.

You can also have a function that runs onload and basically checks to see if the value of the field matches what was specified in the value="" parameter.

webdestroya
Sorry that is just copying what I wrote in my question. To be honest I don't want to disable autocomplete... I think the solution I gave is going to have to be what I use.
Dmitriy Likhten
A: 

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.

Dmitriy Likhten