formik: Checkbox doesn't bind to initialValues
🐛 Bug report
Current Behavior
When using <Field type="checkbox />
and initialValues
the checkbox doesn’t bind.
Expected behavior
<Field type="checkbox" />
should bind to initialValues
Reproducible example
https://codesandbox.io/s/ppy7wyrl0m
Suggested solution(s)
See #1024
Additional context
See #1024
Your environment
Software | Version(s) |
---|---|
Formik | 1.3.1 |
React | 16.5.2 |
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 25 (2 by maintainers)
This workaround is a little simpler, adding the
checked
property on the Field (works since the props get spread onto the input)This is still an issue
I think this is still a problem.
In the following sandbox, the
initialValues
only works when<Field />
isn’t giventype="checkbox"
.https://codesandbox.io/s/p7zlvk86lm
This is pretty sad guys…
This worked as a workaround for me.
@prajavk , It works for me:
I have the same problem. Third formik bug I have run into since starting to use the library last week… faith has been shaken.
Not fixed yet
I was having this issue with a checkbox group, so I’m leaving this here in case someone else has the same problem and google brings them here. This also uses material ui:
Still an issue on 2.2.9
Workaround with react-native
Please suggest work around for checkbox with Field render for formik 1.5.7
Yep, lost an hour or so before realising this is a straight up bug. Please re-open the issue.
The
checked={value}
type workaround is usable but it’s unexpected that initialValues doesn’t workSeems that this is being fixed here #1115
I also think this is still a problem - can’t seem to set checkbox initial values using
initialValues