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
Making Sure Your Forms Don't Suck
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Damian Nicholson
October 23, 2017
Technology
220
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Making Sure Your Forms Don't Suck
Damian Nicholson
October 23, 2017
More Decks by Damian Nicholson
See All by Damian Nicholson
Designing form validation the right way
damian
0
330
Chrome DevTools tips and tricks
damian
0
190
Writing testable, scalable, maintainable rock-solid JavaScript
damian
5
1.6k
Ten Things You Should Know About Jasmine
damian
2
1.1k
Other Decks in Technology
See All in Technology
【CEDEC2026】『GRANBLUE FANTASY: Relink - Endless Ragnarok』のバトル制作事例 ~最高のキャラゲーを目指して~
cygames
PRO
0
230
サイバー捜査員研修(前半)
nomizone
1
1.9k
認知負荷をGemini で溶かす — GKE 基盤「Orbit」における AI エージェントの実践
sansantech
PRO
1
270
取引先から届く 「セキュリティチェックシート」の読み解き方
kamadamakoto
0
140
Goでデータパイプラインを作ろう
sansantech
PRO
0
360
システム思考で問題に対処する
yussak
0
200
メルカリのグローバルアプリで挑んだ AlloyDB 運用と課題解決の実践記
hatappi
0
240
Digitization部 紹介資料
sansan33
PRO
2
7.7k
Master Dataグループ紹介資料
sansan33
PRO
1
4.8k
Pavlokで始める電撃駆動開発
sgrsn
0
180
Software Supply Chain Attackからクラウド環境を守るためにできること
lhazy
2
220
サイバー捜査員研修(後半)
nomizone
1
810
Featured
See All Featured
Faster Mobile Websites
deanohume
310
32k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
890
The Language of Interfaces
destraynor
162
27k
Designing Powerful Visuals for Engaging Learning
tmiket
1
480
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
660
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
56k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
170
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.4k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.8k
My Coaching Mixtape
mlcsv
0
210
Transcript
MAKING SURE YOUR FORMS DON'T SUCK @damian
None
None
None
ACCURATE FASTER CONFIDENT SATISFIED https://alistapart.com/article/inline-validation-in-web-forms
https://baymard.com/blog/inline-form-validation E-Commerce sites containing client side validation 40% 60%
https://baymard.com/blog/inline-form-validation E-Commerce sites containing client side validation 12% 40% 48%
THIS LEADS ME TO BELIEVE IT'S PURELY AN IMPLEMENTATION ISSUE
None
None
None
None
WHY IS IT SO HARD TO DO RIGHT?
BUILT TO BE UNRELIABLE
BUILT TO COMPLEMENT SERVER SIDE VALIDATION
ALIGN* AND SYNCHRONISE VALIDATIONS DECLARED ON THE SERVER
RECONCILE SERVER GENERATED VALIDATIONS WITH THOSE ON THE CLIENT
onKeypress - onChange - onBlur RECONCILE ERRORS MANIFESTED ACROSS DIFFERENT
EVENT PHASES
CONDITIONAL VALIDATIONS DEPENDANT ON OTHER FIELD VALUES
ASYNCHRONOUS VALIDATION
HOW DO WE FIX IT?
JUST BEING AWARE THAT SERVER SIDE VALIDATIONS EXIST
RECONCILE ERRORS MANIFESTED ACROSS DIFFERENT EVENT PHASES onKeypress - onChange
- onBlur
onKeypress - onChange - onBlur RECONCILE ERRORS MANIFESTED ACROSS DIFFERENT
EVENT PHASES
REACT CONCEPT OF INTERNAL STATE MANAGEMENT MAKES MORE SENSE AND
IS EASIER TO MANAGE
const fieldAlias = 'userLogin'; this.setState({ [fieldAlias]: { ...this.state[fieldAlias], value: changeFn('
[email protected]
'),
touched: true, } }, () => { Promise.all(validations.map((fn) => { return fn(this.state.values, this.serverErrors(), fieldAlias, 'onChange'); })) .then(() => { this.setValid() }) .catch((errors) => { this.setInvalid(errors) }); });
REMOVE 1 to 1 MAPPING BETWEEN FIELD VALUES AND VALIDATIONS
const validationFn = (values, serverErrors = {}, fieldUpdated, eventPhase) {
return new Promise((resolve, reject) => { const errors = {}; if (!values.userLogin) { errors.userLogin = 'Please enter your email address'; } Object.assign(errors, serverErrors); if (Object.keys(errors).length === 0) { return resolve(errors); } return reject(errors); }); }; CONDITIONAL VALIDATIONS DEPENDANT ON OTHER FIELDS
const SignInForm = ({ ...props }) => { const {
handleChange, handleBlur, form, method, fields, ...other } = props; const { userLogin, password } = form; return ( <form method={method} action="POST" {...other}> <input type="text" data-alias="userLogin" onChange={handleChange} onBlur={handleBlur} value={userLogin.value} /> {userLogin.touched && userLogin.errors.length > 0 && <span>{userLogin.errors}</span> } ... <button>Sign in</button> </form> ); }; export default conferizeForm(SignInForm, validationFn);
Consolidated event handling - either onChange or onBlur Conditional validations
Sync and async validations declared and resolved using Promise API Composable validations Developers own their form and it's fields Synchronising server and client side validations
MAKES USERS HAPPY BUT ONLY IF DONE RIGHT
REACT MAKES THAT A LOT EASIER
THE END