<input autocomplete='on'> does not w

2019-04-22 03:11发布

I was struggling for a while on the html5 autocomplete feature of Chrome. I had a form like this

<form>
<input name='myname' type='email' autocomplete='on' />
<input type='submit' value='Submit!' onclick='transform_and_post_data();return false;'/>
</form>

When using Firefox and returning to this form autocomplete works fine. But not with Chrome (versions 26 to 30 at least). I finally found that autocomplete saving of a form is done only when calling the GET or POST default action of the form (here prevented by the return false). So I found a work around that fixes it in some situations :

 <form method='post' action='myaction'>
 <input name='myname' type='email' autocomplete='on' />
<input type='submit' value='Submit!' onclick='transform_data();'/>
</form>

This works well as long as I do not need to post my form data through an XhttpRequest. Does any one knows a trick to make Chrome autocomplete forms with XHRs?

Is it a known bug of Chrome? (as Firefox works as expected)

Note : autocomplete='on' should be useless because it is the default behaviour of an input

2条回答
神经病院院长
2楼-- · 2019-04-22 03:35

Chrome will only save the autocomplete information on submit. There are some workarounds detailed here: Trigger autocomplete without submitting a form

查看更多
3楼-- · 2019-04-22 03:39

Please provide ID to your input variable

<form method='post' action='myaction'>
 <input name='myname' type='email' id="myname" autocomplete='on' />
 <input type='submit' value='Submit!' onclick='transform_data();'/>
</form>

Then it should work, without id it wont work

查看更多
登录 后发表回答