Skip to content
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

Fix value type #3961

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/khaki-cherries-appear.md
@@ -0,0 +1,5 @@
---
'formik': patch
---

fix to support number and boolean type for form values
4 changes: 2 additions & 2 deletions packages/formik/src/Formik.tsx
Expand Up @@ -599,7 +599,7 @@ export function useFormik<Values extends FormikValues = FormikValues>({
);

const executeChange = React.useCallback(
(eventOrTextValue: string | React.ChangeEvent<any>, maybePath?: string) => {
(eventOrTextValue: string | number | boolean | React.ChangeEvent<any>, maybePath?: string) => {
// By default, assume that the first argument is a string. This allows us to use
// handleChange with React Native and React Native Web's onChangeText prop which
// provides just the value of the input.
Expand All @@ -608,7 +608,7 @@ export function useFormik<Values extends FormikValues = FormikValues>({
let parsed;
// If the first argument is not a string though, it has to be a synthetic React Event (or a fake one),
// so we handle like we would a normal HTML change event.
if (!isString(eventOrTextValue)) {
if (typeof eventOrTextValue === 'object' && 'nativeEvent' in eventOrTextValue && eventOrTextValue.nativeEvent instanceof Event) {
// If we can, persist the event
// @see https://reactjs.org/docs/events.html#event-pooling
if ((eventOrTextValue as any).persist) {
Expand Down