Top Banner
HTML5 Forms - KISS time
62

HTML5 workshop, forms

Aug 29, 2014

Download

Technology

Robert Nyman

Workshop given at Jfokus 2012
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: HTML5 workshop, forms

HTML5 Forms - KISS time

Page 2: HTML5 workshop, forms

Forms

Page 3: HTML5 workshop, forms

Thou shalt make things simple

Page 4: HTML5 workshop, forms
Page 5: HTML5 workshop, forms
Page 6: HTML5 workshop, forms
Page 7: HTML5 workshop, forms

Types

Page 8: HTML5 workshop, forms

<input type="color">

<input type="date">

<input type="datetime">

<input type="datetime-local">

<input type="email">

<input type="month">

<input type="number">

<input type="range">

<input type="search" results="5" autosave="saved-searches">

<input type="tel">

<input type="time">

<input type="url">

<input type="week">

New form types

Page 11: HTML5 workshop, forms

Attributes

Page 12: HTML5 workshop, forms

<input type="text" autocomplete="off">

<input type="text" autofocus>

<input type="submit" formaction="http://example.org/save" value="Save">

<input type="submit" formenctype="application/x-www-form-urlencoded" value="Save with enctype">

<input type="submit" formmethod="POST" value="Send as POST">

<input type="submit" formnovalidate value="Don't validate">

<input type="submit" formtarget="_blank" value="Post to new tab/window">

New form attributes

Page 13: HTML5 workshop, forms

<input type="text" list="data-list">

<input type="range" max="95">

<input type="range" min="2">

<input type="file" multiple>

<input type="text" readonly>

<input type="text" required>

<input type="text" pattern="[A-Z]*">

<input type="text" placeholder="E.g. Robocop">

<input type="text" spellcheck="true">

<input type="number" step="5">

Page 14: HTML5 workshop, forms

<input type="text" mozactionhint="Next">

Page 15: HTML5 workshop, forms

Elements

Page 16: HTML5 workshop, forms

<input type="text" list="data-list">

<datalist id="data-list"> <option value="Hugo Reyes"> <option value="Jack Shephard"> <option value="James 'Sawyer' Ford"> <option value="John Locke"> <option value="Sayid Jarrah"></datalist>

New form elements

Page 17: HTML5 workshop, forms

<keygen></keygen>

<meter min="0" max="10" value="7"></meter>

<input type="range" id="range"><output for="range" id="output"></output>

<progress max="100" value="70">70%</progress>

Page 18: HTML5 workshop, forms

<input type="range" id="da-range"><output id="da-range-output"></output><script> (function () { var range = document.getElementById("da-range"), output = document.getElementById("da-range-output"); range.addEventListener("input", function () { output.value = this.value; }, false); })();</script>

Page 20: HTML5 workshop, forms

<input type="text" required>

Page 21: HTML5 workshop, forms
Page 22: HTML5 workshop, forms

Only spaces are regarded as input :-(

Page 23: HTML5 workshop, forms

<input type="text" required style="visibility: hidden">

Page 24: HTML5 workshop, forms

No dialog, won't submit form

Dialog at element

No dialog, won't submit form

Dialog at top left of screen (not browser)

Page 25: HTML5 workshop, forms

<input type="email" required>

Page 26: HTML5 workshop, forms
Page 27: HTML5 workshop, forms

No support for international characters, i.e. rö[email protected] won't work

Page 28: HTML5 workshop, forms

<input type="text" pattern="\d{2}\-\d{5}">

Page 29: HTML5 workshop, forms
Page 30: HTML5 workshop, forms

Empty fields are seen as valid

Page 31: HTML5 workshop, forms

<input type="text" title="So you tried to skip me?" required>

Page 32: HTML5 workshop, forms
Page 33: HTML5 workshop, forms

<input type="text" pattern="\d{2}\-\d{5}" x-moz-errormessage="PLEASE, just do it right!">

Page 34: HTML5 workshop, forms
Page 35: HTML5 workshop, forms

elm.setCustomValidity("No, that's wrong!");

Page 36: HTML5 workshop, forms
Page 37: HTML5 workshop, forms

Remove custom validation message by setting it to an empty string...

Page 38: HTML5 workshop, forms

elm.setCustomValidity("");

Page 39: HTML5 workshop, forms

Using setCustomValidity totally kills the checkValidity method

Page 40: HTML5 workshop, forms
Page 41: HTML5 workshop, forms
Page 42: HTML5 workshop, forms

(function () { var oninvalidTest = document.getElementById("oninvalid-test"); oninvalidTest.addEventListener("input", function () { this.setCustomValidity(""); }, false);

oninvalidTest.addEventListener("invalid", function () { this.setCustomValidity("No, that's wrong!"); }, false);})();

Page 43: HTML5 workshop, forms

Styling

Page 44: HTML5 workshop, forms

input:required { border: 1px solid #00f;}

Page 45: HTML5 workshop, forms
Page 46: HTML5 workshop, forms

input:valid { border: 1px solid #0f0;}

input:invalid { border: 1px solid #f00;}

input:out-of-range { border: 1px solid #f00;}

Page 47: HTML5 workshop, forms
Page 48: HTML5 workshop, forms
Page 49: HTML5 workshop, forms

input:focus:invalid { border: 1px solid #f00;}

Page 50: HTML5 workshop, forms

input:-moz-ui-valid { border: 1px solid #0f0;}

input:-moz-ui-invalid { border: 1px solid #f00;}

Page 51: HTML5 workshop, forms

input:-moz-placeholder { color: #f00; background: yellow;}

input::-webkit-input-placeholder { color: #f00; background: yellow;}

Page 52: HTML5 workshop, forms
Page 53: HTML5 workshop, forms

Works in Safari, but only with the text color, not the background

Page 54: HTML5 workshop, forms

input::-webkit-validation-bubble-message { color: #f00; background: #000; border: 10px solid #f00; -webkit-box-shadow: 0 0 0 0;}

input::-webkit-validation-bubble-arrow { background: #ff3456; border-color: orange; -webkit-box-shadow: 0 0 0 0;}

Page 55: HTML5 workshop, forms
Page 56: HTML5 workshop, forms
Page 59: HTML5 workshop, forms
Page 60: HTML5 workshop, forms
Page 61: HTML5 workshop, forms