HTML5 Forms Will Change Your Life

Tiffany B. Brown, Opera Software (@webinista)

LA BarCamp8

April 30, 2011 (use the space bar or scroll with your mouse)

Caveats

See Wufoo's EXCELLENT The Current State of HTML5 Forms (wufoo.com/html5)

Advantages to using HTML5 Forms

(*Still need to validate on the server if you are using one.)

Disadvantages (for now)

Disadvantages aren't so bad

HTML 4 input types and elements

text, password, checkbox, radio, submit, reset, file, hidden, image
select, button, optgroup, option, textarea, label, fieldset, legend

Still okay in HTML5.

New HTML 5 input and elements

search, tel, url, email, datetime, date, color, month, week, time, datetime-local, number, range
accept, autocomplete, dirname, list, max, min, multiple, pattern, placeholder, required, step and more!
datalist, keygen, output, progress, meter

Won’t cover all of these. Also: not all attributes apply to all input types.[1]

Pair with CSS3 pseudo-classes [3]

:checked, :enabled, :disabled, :default, :valid
:invalid, :in-range, :out-of-range, :required, :optional

Awesome forms.

User Interface Enhancements

how they look in Opera for Mac Browser, OS and default errors are language-dependent.

User Interface Enhancements, part 2

WebKit browsers / Mac

What the search field looks like in WebKit browsers What the date field looks
	like in WebKit browsers

Opera 11 / Ubuntu 10

What these fields look like in Opera 11 on Ubuntu

User Interface Enhancements, part 3

Localized errors in Opera
Opera in Japanese

Demo 1: E-mail addresses

<input type="email" name="emailaddy" value=""
placeholder="placeholder@example.com" required>
	

See it in action

Demo 2: Multiple E-mail addresses

<input type="email" name="emailaddy" value=""
placeholder="placeholder@example.com" multiple required>
	

See it in action

Demo 3: U.S. Telephone Numbers

<input type="tel" name="telnum" value=""
placeholder="818-555-1212"
pattern="^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$"
required>

See it in action

Demo includes CSS 3 pseudo-classes and an optional field.

Demo 4: URLs

<input type="url" name="urlfield" value="" required>
	

See it in action

Demo 5: URLs with a pattern

<input type="url" name="urlfield" value=""
placeholder="ftp://"
pattern="^(ftp(?:s)?\:\/\/[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$""
required>
	

See it in action

Demo 6: Range

<input type="range" name="approx"
value="" min="0" max="100" step="5">
	

See it in action

Demo 7: list and <datalist>

<input type="text" name="employee" value="" list="employeelist">
<datalist id="employeelist">
    <option value="Ray Allen">
    <option value="Glenn Davis">
    <option value="Kevin Garnett">
</datalist>

See it in action

Custom error messages

Fall back strategies

Keep doing what we have been:


Remember: These attributes are still a part of the DOM tree.

See a fall back strategy using jQuery