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?
inputmode
attribute, which - if I'm understanding what I read correctly - can be used for specifying what keyboard type should be offered to the user when they interact with the field, without also implying any validation rules. At some point in the future, using theinputmode
attribute instead of thetype
attribute will probably be the correct solution to this problem - but not yet. – Mark Amery$('[inputmode]').each(function () { this.attr({type: this.attr('inputmode'), novalidate: true}) });
– Marnen Laibow-Koserinputmode
would. Doing things your way, you still can't (for example) read non-numeric values that the user types into an input box of typenumber
. For example, try typing something non-numeric into the text box in this fiddle and clicking the button. – Mark Amery<input type='number'>
doesn't accept non-numeric values at all? – Marnen Laibow-Koser