SlideShare a Scribd company logo
Building & Breaking
    Web Forms
     with Quaid-JS


    Chris Lienert
     @cliener
I work for Jardine Lloyd Thompson
Who used to smuggle opium
Insurance means forms
And forms
And more forms
Imagine filling that out online
Or on your mobile
Design Patterns




http://www.lukew.com/resources/web_form_design.asp
Design Patterns

Vertical label/field
Vertical Label/Field
Design Patterns

Vertical label/field
Horizontal (search)
Horizontal (Search)
Design Patterns

Vertical label/field
Horizontal (search)
Clear path to completion
Clear Path to Completion
Design Patterns

Vertical label/field
Horizontal (search)
Clear path to completion
Mark optional fields
Mark Optional Fields
Don’t do this
Build

Form
Build

Form
Fieldset
Build

Form
Fieldset
[no caption]
Build

Form
Fieldset
[no caption]
Block element (p, li, th, td)
Build

Form
Fieldset
[no caption]
Block element (p, li, th, td)
Label (id)
Build

Form
Fieldset
[no caption]
Block element (p, li, th, td)
Label (id)
Field
Build

<form method="post" action="wds.aspx">
<fieldset>
<p><label for="name">Name</label> <input
type="text" name="name" id="name"></p>
</fieldset>
</form>
HTML5 Forms




http://wufoo.com/html5
HTML5 Attributes

maxlength for TextArea
HTML5 Attributes

maxlength for TextArea
required
HTML5 Attributes

maxlength for TextArea
required
placeholder
HTML5 Attributes

maxlength for TextArea
required
placeholder
autocorrect="off "
HTML5 Attributes

maxlength for TextArea
required
placeholder
autocorrect="off "
autocapitalize="off "
HTML5 Attributes

maxlength for TextArea
required
placeholder
autocorrect="off "
autocapitalize="off "
autofocus
Autofocus in Practice – Type…
Autofocus in Practice – Type…
Autofocus in Practice – Argh!
HTML5 Attributes

Pattern
 • default error messages
   are awful
 • doesn't scale well
 • does a fine robot dance
HTML5 Attributes

Pattern
 • pattern="/d*"
HTML5 Input Types

Email
 • instant win
 • iOS keyboard love
HTML5 Input Types

Date, Month, Week, Time
 • don’t
HTML5 Input Types

Tel
 • fairly useless
 • iOS keyboard love
People get things wrong
Validation to the rescue!
You Wouldn’t Like Me When I’m Angry
Validate Early,Validate Often

Allow people to make mistakes
Allow People to Make Mistakes
Allow People to Make Mistakes
Validate Early,Validate Often

Allow people to make mistakes
Clearly mark invalid fields
Clearly Mark Invalid Fields
Clearly Mark Invalid Fields

<p><label for="birth-date">Birth Date</
label> <input type="text" class="date"
name="birth-date" id="birth-date"
required></p>
Clearly Mark Invalid Fields

<p><label for="birth-date">Birth Date</
label> <input type="text" class="date"
name="birth-date" id="birth-date" required
aria-invalid="true">
<label for="birth_date" class="errata"
role="alert">Please enter a value</label></
p>
Validate Early,Validate Often

Allow people to make mistakes
Clearly mark invalid fields
Pattern validate on entry
Pattern Validate on Entry
Validate Early,Validate Often

Allow people to make mistakes
Clearly mark invalid fields
Pattern validate on entry
Enforce minimum not maximum
Enforce Minimum not Maximum
Validate Early,Validate Often

Allow people to make mistakes
Clearly mark invalid fields
Pattern validate on entry
Enforce minimum not maximum
Get it right
Get it Right
A Bunch of Malarkey
Special Exhibit
Special Exhibit
Special Exhibit
Building & Breaking Web Forms with Quaid-JS
Building & Breaking Web Forms with Quaid-JS
Build
Build
Build
Build




        Lots of coding
Quaid JS

Embrace & extend HTML, DOM
Quaid JS

Embrace & extend HTML, DOM
Polyfill older browsers
Embrace and Extend

Tel
 • phone
  <input type="tel" class="phone">

 • mobile
  <input type="tel" class="mobile">
Embrace and Extend

Postcode
 • data-state-field
<input type="text" class="postcode" data-
state-field="state">

<select id="state" name="state">…</ select>
Embrace and Extend

Time
<input type="text" class="time">

Date
<input type="text" class="date">

Year
<input type="text" class="year">
Embrace and Extend

Numeric
<input type="text" class="numeric">

Integer
<input type="text" class="integer">

Currency
<input type="text" class="currency">
Embrace and Extend

Positive Numeric
<input type="text" class="positive_numeric">

Positive Integer
<input type="text" class="positive_integer">

Positive Currency
<input type="text" class="positive_currency">
Embrace and Extend

Credit Card
<input type="text" class="credit_card">

CSC
<input type="text" class="csc">
Data Attributes

Required if
<input type="checkbox" name="variable-field"
id="variable-field">
…
<input type="text" name="target-field"
id="target-field" data-required-
field="variable-field">
Data Attributes

Visible if
<input type="checkbox" name="variable-field"
id="variable-field">
…
<p data-visible-field="variable-field">…</p>
Custom Validation

Inline
$("#field").addValidation(function (el) {
  if (!(el.isValid = !el.checked)) {
    el.errorMessage = "Check the box or else.";
  }
});
Custom Validation

On Submit
$("#field").addSubmitValidation(function (el) {
  if (!(el.isValid = !el.checked)) {
    el.errorMessage = "Check the box or else.
Really.";
  }
});
Custom Validation

Ajax Server Call
$("#postcode").addServerValidation({
  path: "validation.svc/IsValidPostcode?
postcode="
})
Custom Validation

Ajax Service
public ValidationResponse IsValidPostcode(string
postcode, string caller)
{
   using (var p = new PostalAddressClient())
   {
     if (!string.IsNullOrEmpty(postcode) && !
p.IsValidPostcode(postcode))
     {
        …
}
Custom Validation

Ajax Service
public ValidationResponse IsValidPostcode(…)
{
     …
        return new ValidationResponse(…, caller);
     }
  }
  return new ValidationResponse(string.Empty, caller);
}
Custom Validation

Ajax Response
> validationResponse {
  message: "",
  caller: "postcode"
}
Plug-in Internationalisation

Custom methods and errors
quaid.forms-au-4.0.js
message: { required:
 "Value not entered" }

quaid.forms-ca-4.0.js
message: { required:
"Value not entered, eh. Go Leafs!" }
Elephant in the Room
Elephant in the Room




                   6+
And the Rest



6+         3.6+
When the Lights Go Down

JavaScript
HTML5
Server
<label class="server-error">
Ready for the Taking




https://github.com/cliener/Quaid-JS
On a Web Site Near You




http://physical.jltsport.com.au
@cliener
Standing on the Shoulders of Giants
Wufoo
The Current State of HTML5 Forms
http://wufoo.com/html5/

Luke W
Web Form Design: Filling in the Blanks
http://www.lukew.com/resources/web_form_design.asp
Evolving E-commerce Checkout
http://www.lukew.com/ff/entry.asp?1579
Standing on the Shoulders of Giants
Steve Krug
Don't Make Me Think
http://www.sensible.com/dmmt.html

Punkchip
WAI-ARIA to enhance form validation
http://www.punkchip.com/2010/12/aria-enhance-
form-validation/

More Related Content

Building & Breaking Web Forms with Quaid-JS

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n