admin管理员组文章数量:1023764
IMPORTANT: Installing older version of Formik gets rid of this error. I used npm install [email protected] --save
to solve this. Starting with 2.0.8 bug es back.
I was trying to use Formik for the first time and was following a guide, but applying it to my form, where my divs and inputs had different classes and the layout was different but I don't think that's the issue.
I couldn't find in google anyone having this error. I'll add the whole code form the file because some of the problems are possibly because of imports.
This is the error from browser console:
Warning: An unhandled error was caught from submitForm() TypeError: Function has non-object prototype 'undefined' in instanceof check
at Function.[Symbol.hasInstance] (<anonymous>)
at Formik.tsx:757
Error happens when I press submit button when the code is as shown below
import React,{useState} from 'react'
import * as Yup from 'yup'
import {Formik} from 'formik'
import Error from './Error'
const ValidationSchema = Yup.object().shape({
nicknameField: Yup.string().min(1,"Minimal length: 1").max(16, "Maximum length: 16")
.required("Minimum length: 1")
.matches("^[a-zA-Z0-9\\[\\]!@_-]{1,16}$", "Only A-Z, a-z, 0-9, []!@_- characters are allowed")
});
export default function ChooseNickname(){
return(
<Formik initialValues={{nicknameField:""}}
validationSchema={ValidationSchema}
onSubmit={(values, { setSubmitting, resetForm }) => {
// setSubmitting(true);
setTimeout(() => {
alert(JSON.stringify(values, null, 2));
resetForm();
setSubmitting(false);
}, 500);
}
}>
{({values, errors, touched, handleChange, handleBlur, handleSubmit, isSubmitting}) => (
<form onSubmit={handleSubmit}>
<div className="form-group">
<h2 className="font-weight-bold text-dark">Set your nickname</h2>
<input type="text"
className={touched.nicknameField && errors.nicknameField? "form-control is-invalid":"form-control"}
name="nicknameField"
id="nicknameField"
placeholder="nickname"
onChange={handleChange}
onBlur={handleBlur}
value={values.nicknameField}
/>
<pre>{JSON.stringify(values, null, 2)}</pre>
{console.log(errors)}
</div>
<button type="submit" className="btn btn-primary" disabled={false}>Submit</button>
</form>
)}
</Formik>
);
};
But if i change <form onSubmit={handleSubmit}>
to
<form onSubmit={() => {
alert("formik submitting")
}}>
then there is no error, but its obviously useless, because in this case its not a Formik form anymore, validation isnt being done, etc...
IMPORTANT: Installing older version of Formik gets rid of this error. I used npm install [email protected] --save
to solve this. Starting with 2.0.8 bug es back.
I was trying to use Formik for the first time and was following a guide, but applying it to my form, where my divs and inputs had different classes and the layout was different but I don't think that's the issue.
I couldn't find in google anyone having this error. I'll add the whole code form the file because some of the problems are possibly because of imports.
This is the error from browser console:
Warning: An unhandled error was caught from submitForm() TypeError: Function has non-object prototype 'undefined' in instanceof check
at Function.[Symbol.hasInstance] (<anonymous>)
at Formik.tsx:757
Error happens when I press submit button when the code is as shown below
import React,{useState} from 'react'
import * as Yup from 'yup'
import {Formik} from 'formik'
import Error from './Error'
const ValidationSchema = Yup.object().shape({
nicknameField: Yup.string().min(1,"Minimal length: 1").max(16, "Maximum length: 16")
.required("Minimum length: 1")
.matches("^[a-zA-Z0-9\\[\\]!@_-]{1,16}$", "Only A-Z, a-z, 0-9, []!@_- characters are allowed")
});
export default function ChooseNickname(){
return(
<Formik initialValues={{nicknameField:""}}
validationSchema={ValidationSchema}
onSubmit={(values, { setSubmitting, resetForm }) => {
// setSubmitting(true);
setTimeout(() => {
alert(JSON.stringify(values, null, 2));
resetForm();
setSubmitting(false);
}, 500);
}
}>
{({values, errors, touched, handleChange, handleBlur, handleSubmit, isSubmitting}) => (
<form onSubmit={handleSubmit}>
<div className="form-group">
<h2 className="font-weight-bold text-dark">Set your nickname</h2>
<input type="text"
className={touched.nicknameField && errors.nicknameField? "form-control is-invalid":"form-control"}
name="nicknameField"
id="nicknameField"
placeholder="nickname"
onChange={handleChange}
onBlur={handleBlur}
value={values.nicknameField}
/>
<pre>{JSON.stringify(values, null, 2)}</pre>
{console.log(errors)}
</div>
<button type="submit" className="btn btn-primary" disabled={false}>Submit</button>
</form>
)}
</Formik>
);
};
But if i change <form onSubmit={handleSubmit}>
to
<form onSubmit={() => {
alert("formik submitting")
}}>
then there is no error, but its obviously useless, because in this case its not a Formik form anymore, validation isnt being done, etc...
Share Improve this question edited Mar 27, 2020 at 19:26 caribbean asked Mar 27, 2020 at 17:06 caribbeancaribbean 3171 gold badge3 silver badges14 bronze badges1 Answer
Reset to default 1Actually your code is working fine.. I've tested (copy/pasted) it on sandbox with the latest Formik version v2.1.4 and it seems to work.
Not sure but it could be some issue with other libraries in your development environment? or maybe node_modules
cache.
I did some simple modification to make sure and added some missing classes. Check it out at this sandbox
IMPORTANT: Installing older version of Formik gets rid of this error. I used npm install [email protected] --save
to solve this. Starting with 2.0.8 bug es back.
I was trying to use Formik for the first time and was following a guide, but applying it to my form, where my divs and inputs had different classes and the layout was different but I don't think that's the issue.
I couldn't find in google anyone having this error. I'll add the whole code form the file because some of the problems are possibly because of imports.
This is the error from browser console:
Warning: An unhandled error was caught from submitForm() TypeError: Function has non-object prototype 'undefined' in instanceof check
at Function.[Symbol.hasInstance] (<anonymous>)
at Formik.tsx:757
Error happens when I press submit button when the code is as shown below
import React,{useState} from 'react'
import * as Yup from 'yup'
import {Formik} from 'formik'
import Error from './Error'
const ValidationSchema = Yup.object().shape({
nicknameField: Yup.string().min(1,"Minimal length: 1").max(16, "Maximum length: 16")
.required("Minimum length: 1")
.matches("^[a-zA-Z0-9\\[\\]!@_-]{1,16}$", "Only A-Z, a-z, 0-9, []!@_- characters are allowed")
});
export default function ChooseNickname(){
return(
<Formik initialValues={{nicknameField:""}}
validationSchema={ValidationSchema}
onSubmit={(values, { setSubmitting, resetForm }) => {
// setSubmitting(true);
setTimeout(() => {
alert(JSON.stringify(values, null, 2));
resetForm();
setSubmitting(false);
}, 500);
}
}>
{({values, errors, touched, handleChange, handleBlur, handleSubmit, isSubmitting}) => (
<form onSubmit={handleSubmit}>
<div className="form-group">
<h2 className="font-weight-bold text-dark">Set your nickname</h2>
<input type="text"
className={touched.nicknameField && errors.nicknameField? "form-control is-invalid":"form-control"}
name="nicknameField"
id="nicknameField"
placeholder="nickname"
onChange={handleChange}
onBlur={handleBlur}
value={values.nicknameField}
/>
<pre>{JSON.stringify(values, null, 2)}</pre>
{console.log(errors)}
</div>
<button type="submit" className="btn btn-primary" disabled={false}>Submit</button>
</form>
)}
</Formik>
);
};
But if i change <form onSubmit={handleSubmit}>
to
<form onSubmit={() => {
alert("formik submitting")
}}>
then there is no error, but its obviously useless, because in this case its not a Formik form anymore, validation isnt being done, etc...
IMPORTANT: Installing older version of Formik gets rid of this error. I used npm install [email protected] --save
to solve this. Starting with 2.0.8 bug es back.
I was trying to use Formik for the first time and was following a guide, but applying it to my form, where my divs and inputs had different classes and the layout was different but I don't think that's the issue.
I couldn't find in google anyone having this error. I'll add the whole code form the file because some of the problems are possibly because of imports.
This is the error from browser console:
Warning: An unhandled error was caught from submitForm() TypeError: Function has non-object prototype 'undefined' in instanceof check
at Function.[Symbol.hasInstance] (<anonymous>)
at Formik.tsx:757
Error happens when I press submit button when the code is as shown below
import React,{useState} from 'react'
import * as Yup from 'yup'
import {Formik} from 'formik'
import Error from './Error'
const ValidationSchema = Yup.object().shape({
nicknameField: Yup.string().min(1,"Minimal length: 1").max(16, "Maximum length: 16")
.required("Minimum length: 1")
.matches("^[a-zA-Z0-9\\[\\]!@_-]{1,16}$", "Only A-Z, a-z, 0-9, []!@_- characters are allowed")
});
export default function ChooseNickname(){
return(
<Formik initialValues={{nicknameField:""}}
validationSchema={ValidationSchema}
onSubmit={(values, { setSubmitting, resetForm }) => {
// setSubmitting(true);
setTimeout(() => {
alert(JSON.stringify(values, null, 2));
resetForm();
setSubmitting(false);
}, 500);
}
}>
{({values, errors, touched, handleChange, handleBlur, handleSubmit, isSubmitting}) => (
<form onSubmit={handleSubmit}>
<div className="form-group">
<h2 className="font-weight-bold text-dark">Set your nickname</h2>
<input type="text"
className={touched.nicknameField && errors.nicknameField? "form-control is-invalid":"form-control"}
name="nicknameField"
id="nicknameField"
placeholder="nickname"
onChange={handleChange}
onBlur={handleBlur}
value={values.nicknameField}
/>
<pre>{JSON.stringify(values, null, 2)}</pre>
{console.log(errors)}
</div>
<button type="submit" className="btn btn-primary" disabled={false}>Submit</button>
</form>
)}
</Formik>
);
};
But if i change <form onSubmit={handleSubmit}>
to
<form onSubmit={() => {
alert("formik submitting")
}}>
then there is no error, but its obviously useless, because in this case its not a Formik form anymore, validation isnt being done, etc...
Share Improve this question edited Mar 27, 2020 at 19:26 caribbean asked Mar 27, 2020 at 17:06 caribbeancaribbean 3171 gold badge3 silver badges14 bronze badges1 Answer
Reset to default 1Actually your code is working fine.. I've tested (copy/pasted) it on sandbox with the latest Formik version v2.1.4 and it seems to work.
Not sure but it could be some issue with other libraries in your development environment? or maybe node_modules
cache.
I did some simple modification to make sure and added some missing classes. Check it out at this sandbox
本文标签: javascriptFormik submitForm() TypeErrorStack Overflow
版权声明:本文标题:javascript - Formik submitForm() TypeError - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745519767a2154261.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论