jaredpalmer / formik

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

executeBlur should not inspect `event` if `path` is set #1113

Open danielberndt opened 6 years ago

danielberndt commented 6 years ago

🐛 Bug report

I've created a FieldWrapper that looks somewhat like this:

const MyField ({name, as: Component}) => (
  <Field name={name}>
     {({field: {onChange, onBlur, ...rest}, form}) => (
       <Component
           onBlur={onBlur(name)}
           onChange={onChange(name)}
           {...rest}
       />
   )}</Field>
)

I'm using this to wrap external Inputs. Those Inputs don't always pass an event when firing onBlur though. I expected this to be fine by formik, because I passed the name of the corresponding field explicitly.

It turns out though that the following lines still try to access the event, even though there's no need to when the path is explicitly passed. https://github.com/jaredpalmer/formik/blob/85d15b302cd776eb615064a4451e1a7575b1439d/src/Formik.tsx#L444-L445

Is it possible/reasonable to rewrite those lines in a way that e is not accessed when the path is passed?

jaredpalmer commented 5 years ago

Agree, I fixed this in v2. They should use the override.