jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.98k stars 2.79k forks source link

validateOnChange doesn't function as expected #237

Closed joelhooks closed 7 years ago

joelhooks commented 7 years ago

I've got a relatively simple form that has a textarea. When I load the form and type into it, while the errors object updates to show that errors exist, the isValid property doesn't change until I blur.

When I refocus the input and type it updates isValid as expected.

https://codesandbox.io/s/93406xym0y

This occurs in the README examples as well, and I'm wondering if my expectations aren't correct.

joelhooks commented 7 years ago

I don't know what, if any, the ramifications are for this, but the field is definitely touched and dirty at this point.

https://github.com/eggheadio/formik/commit/a86ac25c4c15f6cdc60a734c691084fc85ef6f23

jaredpalmer commented 7 years ago

@joelhooks Yeah I think this part of the API could use some love or better docs:

@eonwhite Going forward it might make sense to be more explicit and introduce:

const EggheadFormik = ({ render, ...props }) => 
  <Formik 
     {...props} 
     render={p =>  render({...p,  hasChanged: !deepEqual(p.values, p.initialValues)})} 
   />
jaredpalmer commented 7 years ago

@joelhooks Here's a demo of how I would go about it https://codesandbox.io/s/jn00j0prpv

joelhooks commented 7 years ago

I'll just maintain a fork. Thanks @jaredpalmer!