This is a follow up on my previous post. It intends to go into greater detail about form fields in HTML 5.
Using HTML 5 Forms
Firstly webforms2 seems to have a javascript implementation so that you can use these in all modern web browsers. The library seems to be adapting itself, but should be pretty bombproof for html5 soon.
With this you can start using
<input type="email"/> <input type="date"/> <input type="url"/>
all immediately.
Required Fields
There are however some bonus options. I mentioned input required in my previous post – as my commenter points out – it should be:
<input required="required"/>
Bespoke Validation
There is also the neat pattern attributes which allows you to bespoke regular expression validation for a field
<input type="text" pattern="^([A-PR-UWYZ][A-HK-Y0-9][A-HJKS-UW0-9]?
[ABEHMNPRVWXY0-9]?{1,2} [0-9][ABD-HJLNP-UW-Z]{2})$" />
<!-- uk postal code -->
Placeholder
Placeholder is some text that provides a hint to the user about what to type. It isn’t the default value. I have seen this hacked in with Javascript several times before. Its a really good nice to have feature that can be implemented really cheaply.
Javascript and Handlers
For the form level. You can now call checkValidity() on the form to check the validity of the form.
When you submit a form using submit() with a scripted-submit tag present.
Finally if you want to do bespoke validations to a form and use the built in form validation. You can set a custom validity for the field using setCustomValidity(). An empty string indicates validity, anything else indicates an error.
Joel