When using <Field type="checkbox /> and initialValues the checkbox doesn't bind.
<Field type="checkbox" /> should bind to initialValues
https://codesandbox.io/s/ppy7wyrl0m
See #1024
See #1024
| Software | Version(s) |
| ---------------- | ---------- |
| Formik | 1.3.1
| React | 16.5.2
This worked as a workaround for me.
const CheckboxInput = (props) => (
<Field {...props} render={({field}) => <input {...field} type="checkbox" checked={field.value} />} />
);
This workaround is a little simpler, adding the checked property on the Field (works since the props get spread onto the input)
<Field type="checkbox" name="box" checked={props.values.box} />
Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal.
ProBot automatically closed this due to inactivity. Holler if this is a mistake, and we'll re-open it.
I think this is still a problem.
In the following sandbox, the initialValues only works when <Field /> isn't given type="checkbox".
I also think this is still a problem - can't seem to set checkbox initial values using initialValues
Seems that this is being fixed here #1115
This is still an issue
This is pretty sad guys...
It's out in v2-rc.5
https://github.com/jaredpalmer/formik/releases/tag/v2.0.1-rc.5
Updated the initial codesandbox to Formik 2 and React 16.8.6 (something with hooks)
https://codesandbox.io/s/formik-v2-field-checkbox-binding-vdvty
Please suggest work around for checkbox with Field render for formik 1.5.7
Please suggest work around for checkbox with Field render for formik 1.5.7
@prajavk , It works for me:
<Field type="checkbox" name="manual-only" id="manual-only" onChange={event => setFieldValue('manualOnly', event.target.checked)} checked={values.manualOnly} />
Workaround with react-native
<CheckBox color="#000"
onPress={event =>
props.setFieldValue("terms", !props.values.terms)
}
checked={props.values.terms}
/>
Still experience this in formik 1.5.8
Hoping more comments results in this getting patched.
Followed @RazerM 's comment and removed type="checkbox" as a workaround.
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
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 work
Most helpful comment
This is still an issue