-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update "form.touched" to suport nested fields #413
Comments
This is a typescript issue. |
Can you paste in your code that is through the bug? |
Sure. Here is the
And then, in my
The TS error ( Looking at the type definition, it seems that I tried searching for a way to get keys of nested objets the same way you're currently doing with |
Correct way to handle this: <Formik
initialValues={{ business: { name: '' } }}
onSubmit={values => console.log(values)}
render={({
values,
handleChange,
handleBlur,
}: FormikProps<{ business: { name: string } }>) => (
<Form>
<Field
name="business.name"
render={({
field,
form,
}: FieldProps<{ business: { name: string } }>) => (
<div className="field">
<div className="control">
<input
{...field}
type="text"
placeholder="Business Name"
className={
form.touched.business &&
form.touched.business.name &&
form.errors.business &&
form.errors.business.name
? 'input is-danger'
: 'input'
}
/>
</div>
</div>
)}
/>
</Form>
)}
/> |
Nice! Got it working with your PR. Thanks! |
Related to #368
Bug, Feature, or Question?
Bug
Current Behavior
FormikTouched
only allows one level of nesting. TypeScript complains if it's nested further:[ts] Property 'name' does not exist on type 'boolean'.
Desired Behavior
With the "Deep State" update I'd think that nested fields would also work.
Suggested Solutions
Not sure if this is an implementation issue or a TypeScript definition issue.
Info
The text was updated successfully, but these errors were encountered: