Tuesday, January 29, 2013

FireFox prefill and autocomplete="off"

FireFox has the ability to record every value you enter into fields on web pages, and if you visit that page again, it will prefill those fields with the last known value when you refresh a page, go back or revisit that page.

I suppose this is useful for the everyday user but this behaviour is on by default and it overrides when a web developer explicitly states what they want the initial state of the fields to be. This includes things like the "value" attribute of a text field, the "checked" attribute of a checkbox or radio button, the "selected" attribute of an option, and specific content in a text area. Thankfully they seem to draw the line a prefilling a password field.

The behaviour may also if client script events don't take this behaviour into account.

So if you want to to be able to set the initial state of your controls, or you want to ensure that your fields start in their default state such as an empty text field, then you will need to add autocomplete="off" to your controls to tell FireFox to leave them alone.

This works even though "autocomplete" to me means something completely different, but I guess W3 though that adding another attribute prefill="off" or firefoxleavethisdammfieldalone="true" would be overkill.

Another option is to have a little bit of client script that presets the fields and then enable client side events after that. This option might be more useful in an ajax driven page.

No comments:

Post a Comment