Skip to content

Commit

Permalink
fix[FastField]: initial values in case of radio and checkbox (#2874)
Browse files Browse the repository at this point in the history
Resolves - #2297

As FastField doesn't set initial values when the input type is radio or checkbox
  • Loading branch information
maddhruv authored Nov 7, 2020
1 parent 658e785 commit 958d67c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-dragons-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'formik': patch
---

fix FastField initial value when input type is radio or checkbox
10 changes: 1 addition & 9 deletions packages/formik/src/FastField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,7 @@ class FastFieldInner<Values = {}, Props = {}> extends React.Component<
validationSchema: _validationSchema,
...restOfFormik
} = formik;
const field = {
value:
props.type === 'radio' || props.type === 'checkbox'
? props.value // React uses checked={} for these inputs
: getIn(formik.values, name),
name,
onChange: formik.handleChange,
onBlur: formik.handleBlur,
};
const field = formik.getFieldProps({ name, ...props });
const meta = {
value: getIn(formik.values, name),
error: getIn(formik.errors, name),
Expand Down

1 comment on commit 958d67c

@vercel
Copy link

@vercel vercel bot commented on 958d67c Nov 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.