Skip to content

Commit

Permalink
test(core/presentation): Re-add removed isInitialValid logic (#7627)
Browse files Browse the repository at this point in the history
Turns out this wasn't as unnecessary as I thought.
isInitialValid is _always_ used if the form when `formik.dirty === false`
It doesn't matter if you have validated the form once or twice or a million times.
  • Loading branch information
christopherthielen authored and mergify[bot] committed Nov 12, 2019
1 parent 956b43b commit f93a278
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function SpinFormikImpl<Values extends {}>(props: FormikConfig<Values>, ref?: Re
const [refSaved, setRefSaved] = React.useState(false);
const [ready, setReady] = React.useState(false);

const defaultIsInitialValid = () => formikRef.current && Object.keys(formikRef.current.state.errors).length === 0;

// When a form is reloaded with existing data, we usually want to show validation errors immediately.
// When the form is first rendered, mark all fields in initialValues as "touched".
// Then run initial validation.
Expand All @@ -40,6 +42,7 @@ function SpinFormikImpl<Values extends {}>(props: FormikConfig<Values>, ref?: Re
<Formik<Values>
ref={saveRef}
{...props}
isInitialValid={props.isInitialValid || defaultIsInitialValid}
render={renderProps => ready && props.render && props.render(renderProps)}
/>
);
Expand Down

0 comments on commit f93a278

Please sign in to comment.