Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
A Sensational Exposé with Bewildering Demonstra...
Search
Peter Gasston
April 18, 2011
Programming
1
53
A Sensational Exposé with Bewildering Demonstrations!
On the HTML5 Constraint Validation API
Peter Gasston
April 18, 2011
Tweet
Share
More Decks by Peter Gasston
See All by Peter Gasston
People Don’t Change
stopsatgreen
0
150
Your Reality Here
stopsatgreen
0
86
Growing Up, Getting Serious - #SotB6
stopsatgreen
1
340
Growing Up, Getting Serious
stopsatgreen
0
86
Surveying the Landscape — November 2016
stopsatgreen
1
150
Surveying the Landscape - Fronteers
stopsatgreen
2
470
The Web vs. The Browser
stopsatgreen
0
180
Surveying the Landscape Sept. 2016
stopsatgreen
1
370
Surveying the Landscape
stopsatgreen
4
810
Other Decks in Programming
See All in Programming
PHPでWebSocketサーバーを実装しよう2025
kubotak
0
220
VS Code Update for GitHub Copilot
74th
1
410
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
140
XP, Testing and ninja testing
m_seki
3
200
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
220
都市をデータで見るってこういうこと PLATEAU属性情報入門
nokonoko1203
1
570
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
20
3.7k
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
160
童醫院敏捷轉型的實踐經驗
cclai999
0
190
第9回 情シス転職ミートアップ 株式会社IVRy(アイブリー)の紹介
ivry_presentationmaterials
1
240
ふつうの技術スタックでアート作品を作ってみる
akira888
0
140
DroidKnights 2025 - 다양한 스크롤 뷰에서의 영상 재생
gaeun5744
3
330
Featured
See All Featured
Typedesign – Prime Four
hannesfritz
42
2.7k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
229
22k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
490
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Adopting Sorbet at Scale
ufuk
77
9.4k
Automating Front-end Workflow
addyosmani
1370
200k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
Building Applications with DynamoDB
mza
95
6.5k
Transcript
A Sensational ExposÉ With Bewildering Demonstrations By Peter Gasston Broken-links.com
@stopsatgreen
None
HARRY HOUDINI
None
None
None
None
CONSTRAINT validation
CONSTRAIN: 1. Severely restrict scope, extent, or activity 2. confine
forcibly, as by bonds.
None
NEW INPUT TYPES <input type= <input type=" "email email" ">
> <input type= <input type=" "url url" "> > <input type= <input type=" "tel tel" "> > <input type= <input type=" "search search" "> >
None
NEW INPUT TYPES <input type= <input type=" "number number" ">
> <input type= <input type=" "range range" "> >
None
NEW JS Methods stepUp()/stepDown() stepUp()/stepDown() valueAsNumber valueAsNumber NEW JS FUNCTION
NEW INPUT TYPES <input type= <input type=" "datetime datetime" ">
> <input type= <input type=" "date date" "> > <input type= <input type=" "month month" "> > <input type= <input type=" "week week" "> > <input type= <input type=" "time time" "> >
None
NEW JS FUNCTION valueAsDate valueAsDate
wufoo.com/html5/
ADDING THE CONSTRAINTs
REQUIRED ATTRIBUTE < <input type= input type=" "text text" "
required required> > < <input type="text" input type="text" required required= ="" ""> > < <textarea textarea required required= ="" "" /> />
REQUIRED ATTRIBUTE
SET THE ERROR MESSAGE < <input type= input type=" "text
text" " x-moz-errormessage x-moz-errormessage ="FooBar"> ="FooBar">
SET THE ERROR MESSAGE
Pattern matching <input type= <input type=" "email email" "> >
<input type= <input type="date" "date"> > <input type= <input type=" "url url" " required> required>
Pattern matching
Pattern ATTRIBUTE < <input type= input type=" "text text" "
pattern="[-0-9]+" pattern="[-0-9]+"> >
CONTEXTUAL ERROR MESSAGES < <input type= input type=" "text text"
" pattern="[-0-9]+" pattern="[-0-9]+" title="Must be a title="Must be a number" number"> >
None
LIMIT MAtching < <input type= input type="number" "number" max="2" max="2">
> < <input type= input type="range" "range" min="0" min="0" max="1" step="0.1" max="1" step="0.1"> > < <input type= input type="text" "text" maxlength="20" maxlength="20"> >
None
None
None
BONUS SLIDE! CSS3 UI pseudo-classes for CSS3 UI pseudo-classes for
styling form states: styling form states: :required :required :optional :optional :valid :valid :invalid :invalid :default :default :in-range :in-range :out-of-range :out-of-range
CONSTRAINT VALIDATION A.P.I.
Is the api present? var hasValidation = var hasValidation =
(myForm. (myForm.checkValidity checkValidity) ) ? true : false; ? true : false;
None
Do not validate < <form form novalidate> novalidate> < <button
button formnovalidate> formnovalidate>
Do not validate if(hasValidation === true) { if(hasValidation === true)
{ myForm. myForm. setAttribute(' setAttribute('novalidate novalidate',''); ',''); } }
Feature detection function formSubmit(evt) { function formSubmit(evt) { (hasValidation ===
true) ? (hasValidation === true) ? newValidation() : newValidation() : oldValidation(); oldValidation(); evt.preventDefault(); evt.preventDefault(); } }
BONUS SLIDe! HTML5 Form Events: HTML5 Form Events: oncontextmenu oncontextmenu
onformchange onformchange onforminput onforminput oninput oninput oninvalid oninvalid
DOES THE FORM VALIDATE? myForm. myForm.checkValidity(); checkValidity();
document.getElementById document.getElementById ('x'). ('x').willValidate; willValidate; Which ELEMENTs will VALIDATE?
Which ELEMENTs will VALIDATE? var formNodes = var formNodes =
myForm.childNodes.length; myForm.childNodes.length; for(i=0; i<formNodes; i++) for(i=0; i<formNodes; i++) { { if(myForm.childNodes[i] if(myForm.childNodes[i]. . willValidate willValidate) { ) { doSomething doSomething; ; } } } }
DOES A field VALIDATE? thisNode. thisNode. checkValidity(); checkValidity();
Validation status thisNode thisNode. .validity; validity;
Validity object customError customError patternMismatch patternMismatch rangeOverflow rangeOverflow rangeUnderflow rangeUnderflow
stepMismatch stepMismatch tooLong tooLong typeMismatch typeMismatch valid valid valueMissing valueMissing
Validity object for(var v in thisNode.validity) { for(var v in
thisNode.validity) { if (thisNode. if (thisNode.validity validity[v] === true) { [v] === true) { var errorMessage; var errorMessage; switch(v){ switch(v){ case 'valueMissing' : case 'valueMissing' : errorMessage = 'FooBar'; errorMessage = 'FooBar'; break; break; } } } }
SET THE ERROR MESSAGE thisNode. thisNode. setCustomValidity setCustomValidity (errorMessage); (errorMessage);
GET THE ERROR MESSAGE document. document. getElementById('x'). getElementById('x'). validationMessage; validationMessage;
alert('The error message is: ' alert('The error message is: '
+ thisNode. + thisNode.validationMessage validationMessage); );
BONUS SLIDE! Javascript library Javascript library to polyfill HTML5 to
polyfill HTML5 form support: form support: http://thecssninja.c http://thecssninja.c om/javascript/H5F om/javascript/H5F
ESCAPING THE CONSTRAINTs
THE END
BONUS SLIDE! Resources: Resources: http://www.broken- http://www.broken- links.com/2011/03/28/html links.com/2011/03/28/html 5-form-validation/ 5-form-validation/
https://developer.mozilla https://developer.mozilla .org/en/HTML/HTML5/Forms_ .org/en/HTML/HTML5/Forms_ in_HTML5 in_HTML5
THANK You. By Peter Gasston Broken-links.com @stopsatgreen