Slide 1

Slide 1 text

MAKING SURE YOUR FORMS DON'T SUCK @damian

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

ACCURATE FASTER CONFIDENT SATISFIED https://alistapart.com/article/inline-validation-in-web-forms

Slide 6

Slide 6 text

https://baymard.com/blog/inline-form-validation E-Commerce sites containing client side validation 40% 60%

Slide 7

Slide 7 text

https://baymard.com/blog/inline-form-validation E-Commerce sites containing client side validation 12% 40% 48%

Slide 8

Slide 8 text

THIS LEADS ME TO BELIEVE IT'S PURELY AN IMPLEMENTATION ISSUE

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

WHY IS IT SO HARD TO DO RIGHT?

Slide 14

Slide 14 text

BUILT TO BE UNRELIABLE

Slide 15

Slide 15 text

BUILT TO COMPLEMENT SERVER SIDE VALIDATION

Slide 16

Slide 16 text

ALIGN* AND SYNCHRONISE VALIDATIONS DECLARED ON THE SERVER

Slide 17

Slide 17 text

RECONCILE SERVER GENERATED VALIDATIONS WITH THOSE ON THE CLIENT

Slide 18

Slide 18 text

onKeypress - onChange - onBlur RECONCILE ERRORS MANIFESTED ACROSS DIFFERENT EVENT PHASES

Slide 19

Slide 19 text

CONDITIONAL VALIDATIONS DEPENDANT ON OTHER FIELD VALUES

Slide 20

Slide 20 text

ASYNCHRONOUS VALIDATION

Slide 21

Slide 21 text

HOW DO WE FIX IT?

Slide 22

Slide 22 text

JUST BEING AWARE THAT SERVER SIDE VALIDATIONS EXIST

Slide 23

Slide 23 text

RECONCILE ERRORS MANIFESTED ACROSS DIFFERENT EVENT PHASES onKeypress - onChange - onBlur

Slide 24

Slide 24 text

onKeypress - onChange - onBlur RECONCILE ERRORS MANIFESTED ACROSS DIFFERENT EVENT PHASES

Slide 25

Slide 25 text

REACT CONCEPT OF INTERNAL STATE MANAGEMENT MAKES MORE SENSE AND IS EASIER TO MANAGE

Slide 26

Slide 26 text

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) }); });

Slide 27

Slide 27 text

REMOVE 1 to 1 MAPPING BETWEEN FIELD VALUES AND VALIDATIONS

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

const SignInForm = ({ ...props }) => { const { handleChange, handleBlur, form, method, fields, ...other } = props; const { userLogin, password } = form; return ( {userLogin.touched && userLogin.errors.length > 0 && {userLogin.errors} } ... Sign in ); }; export default conferizeForm(SignInForm, validationFn);

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

MAKES USERS HAPPY BUT ONLY IF DONE RIGHT

Slide 32

Slide 32 text

REACT MAKES THAT A LOT EASIER

Slide 33

Slide 33 text

THE END