In my forms, I'd like to use the new HTML5 form types, for example <input type="url" />
(more info about the types here).
The problem is that Chrome wants to be super helpful and validate these elements for me, except that it sucks at it. If it fails the built-in validation, there's no message or indication other than the element getting focus. I prefill URL elements with "http://"
, and so my own custom validation just treats those values as empty strings, however Chrome rejects that. If I could change its validation rules, that would work too.
I know I could just revert back to using type="text"
but I want the nice enhancements using these new types offers (eg: it automatically switches to a custom keyboard layout on mobile devices):
So, is there a way to switch off or customise the automatic validation?
Here is the function I use to prevent chrome and opera from showing the invalid input dialog even when using novalidate.
Just use novalidate in your form.
Cheers!!!
If you want to disable client side validation for a form in HTML5 add a novalidate attribute to the form element. Ex:
See https://www.w3.org/TR/html5/sec-forms.html#element-attrdef-form-novalidate
I just wanted to add that using the novalidate attribute in your form will only prevent the browser from sending the form. The browser still evaluates the data and adds the :valid and :invalid pseudo classes.
I found this out because the valid and invalid pseudo classes are part of the HTML5 boilerplate stylesheet which I have been using. I just removed the entries in the CSS file that related to the pseudo classes. If anyone finds another solution please let me know.
Instead of trying to do an end run around the browser's validation, you could put the
http://
in as placeholder text. This is from the very page you linked:It wouldn't be exactly the same since it wouldn't provide that "starting point" for the user, but it's halfway there at least.
I found a solution for Chrome with CSS this following selector without bypassing the native verification form who can be very useful.
By this way, you can also customise your message...
I get the solution on this page : http://trac.webkit.org/wiki/Styling%20Form%20Controls