tamir
tamir

Reputation: 3297

Firefox caches hidden inputs

I have a hidden input field in my form. I noticed that if that field's value is changed by javascript, and then the user refreshes the page, that same value will be set when the page reloads. From what I've seen, this only happens in Firefox.

I've solved this unwanted behaviour by adding autocomplete="off" to that hidden input, but W3C doesn't like this solution, and if i validate the page I get the error:

Attribute autocomplete not allowed on element input at this point.

Apparently, the autocomplete attribute works only on specific inputs - see here.

So is there any solution that will satisfy both W3C and Firefox?

Upvotes: 18

Views: 6376

Answers (2)

Moo
Moo

Reputation: 890

Alternatively, you could use <input type="text" style="display: none;" autocomplete="off" /> instead. It's a bit of a hack, but it should work!

The caching in Firefox is actually quite a good feature a lot of the time, but it does cause some problems when you build more dynamic forms.

Upvotes: 4

jmlnik
jmlnik

Reputation: 2887

To validate (which I wouldn't put as much effort into as you are) I think you could use autocomplete="off" on the entire form, then turn it back on selectively, like this:

<!DOCTYPE html>
<html>
<head>
    <title>TEST</title>
</head>
<body>
    <form autocomplete="off">
        <input type="hidden" name="test">
        <input type="text" name="otherfield" autocomplete="on">
    </form>
</body>
</html>

I initially thought this was a Firefox bug but after discussion with robertc in the comments, I think expected behavior depends on specific use cases. The spec doesn't allow autocompletion on hidden fields so my first reaction still feels right, but Firefox's implementation might have some good arguments to support it. Please comment.

Upvotes: 13

Related Questions