Slide 1

Slide 1 text

Cross-browser HTML5 Forms without repeating repeating yourself Stu Cox [email protected]

Slide 2

Slide 2 text

What's new? ● Input types email, tel, url, number, date, time, search, color... ● Validation required, pattern ● Accessibility / usability autofocus, accesskey, autocomplete, placeholder, datalist, spellcheck ● Javascript APIs

Slide 3

Slide 3 text

EmailField() ↳ DateTimeField() ↳ IntegerField(max_value=5) ↳ CharField(max_length=100, required=True) ↳ Django libraries: criteria

Slide 4

Slide 4 text

django-floppyforms.readthedocs.org ● Moves markup to template snippets ● Drop-in replacement for django.forms ● Baked-in support for HTML5 Django-floppyforms from floppyforms import forms class EventForm(forms.Form): start = forms.DateTimeField() ...

Slide 5

Slide 5 text

<> Markup {% for field in form %} {{ field.label }}: {{ field }} {% endfor %} Start: ...

Slide 6

Slide 6 text

Browser Widgets

Slide 7

Slide 7 text

● Differ between browsers Maybe not a problem? ● Lack of customisation Date/time formats Styling ● Sparse support Graceful fallback, but not very usable Browser Widgets

Slide 8

Slide 8 text

● Nice-to-have Already validating on server Usability gain on mobile ● Lack of customisation Error message wording, styling ● Validation client/server split Usability confusion Duplicated logic Validation

Slide 9

Slide 9 text

☐ Semantic markup ☐ Customisable, styleable widgets ☐ Touch-friendly mobile widgets ☐ Datetime widget ☐ Customisable, styleable validation messages ☐ DRY validation logic All I want for Christmas

Slide 10

Slide 10 text

scSplitDateTime github.com/stucox/scSplitDateTime ● Client-side tool ● Splits datetime field into date & time Webshim afarkas.github.com/webshim ● Polyfills JS APIs & widgets (via jQuery UI) ● Allows custom styling of validation messages ● Custom widgets in all browsers option Library magic

Slide 11

Slide 11 text

☑ Semantic markup Django-floppyforms ☑ Customisable, styleable widgets Webshim + jQuery UI + Modernizr.touch ☐ Touch-friendly mobile widgets Modernizr.touch? ☑ Datetime widget scSplitDateTime ☑ Customisable, styleable validation messages Webshim ☐ DRY validation logic Share logic between client & server? All I want for Christmas