Require autocomplete attribute to be valid
- Rule ID:
- valid-autocomplete
- Category:
- HTML syntax and concepts
- Standards:
- HTML5
The HTML5 autocomplete attribute can be used in different ways:
- On a
<form>element it can take theonoroffvalues to set the default for all nested controls. - On form controls it can either take
onoroffto enable and disable or it can take a number of space-separated tokens describing what type of autocompletion to use. - With the exception that
<input type="hidden">cannot useonoroff.
Further the space-separated tokens must appear in the following order:
- An optional section name (
section-prefix). - An optional
shippingorbillingtoken. - An optional
home,work,mobile,faxorpagertoken (for field names supporting it). - A required field name.
- An optional
webauthntoken.
Typical field names would be:
nameusernamecurrent-passwordaddress-line1country-name- etc
For a full list of valid field names refer to the HTML5 standard Autofill section.
Some field names can only be used on specific input controls, for instance:
- A
new-passwordfield cannot be used on<input type="number"> - A
cc-exp-monthfield cannot be used on<input type="date"> - etc
Again, refer to the Autofill section in the standard for a full table of allowed controls.
Rule details
Examples of incorrect code for this rule:
<input type="text" autocomplete="foo">
<input type="text" autocomplete="name billing">
<input type="text" autocomplete="street-address">
Examples of correct code for this rule:
<input type="text" autocomplete="name">
<input type="text" autocomplete="billing name">
<textarea autocomplete="street-address"></textarea>
References
Version history
- 8.15.0 - Rule added.