Trainer thoughts on web design techs and tools

The required attribute doesn’t work for the color input type in Google Chrome 8 and Safari 5 – the WebKit browsers. Consider the following code:

1
2
3
<input type="text" name="c" id="c" required placeholder="Enter Color">
<button type="button"
  onclick="alert(document.getElementById('c').validity.valid)">check</button>

Clicking the Check button before filling in the field results in a “false” alert. That is correct as the required attribute indicates that the field must be filled out.

Now change the type from “text” to “color” like so:

1
2
3
<input type="color" name="c" id="c" required placeholder="Enter Color">
<button type="button"
  onclick="alert(document.getElementById('c').validity.valid)">check</button>

Again, click the Check button before filling in the field. Now the alert reads “true.” And that is a bug.

I tested the same thing in Opera 10.6 and Firefox 4 (beta) and both appropriately alert “false” when the color field is left empty.

No TweetBacks yet. (Be the first to Tweet this post)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

© Webucator, Inc. All rights reserved. | Toll Free: 877-932-8228 | UK: 0808-101-3484 | From outside the USA: 315-849-2724 | Fax: 315-849-2723