Open al-ani opened 5 years ago
I tried to reproduce the issue here https://codesandbox.io/s/formik-example-z1yuc end up getting similar error.
I suppose if there is a form level validation in the code above, there is no field level validation so there is no validate
prop passed down to Field
like in an example in docs. validateField
function assumes that the field you passed have it's own validate
prop defined (source).
So the solution might be splitting validation logic into validate
props of each Field
https://codesandbox.io/s/formik-example-lu6yu Hope that will help with your problem.
I am using the MATERIAL-UI components, therefore I cannot use Field component. Are you going to fix this bug?
In fact you can use your own JSX component, so is Material UI. And you will get fieldProps passes as argument in the render function.
// Renders an HTML <input> and passes FieldProps field property
<Field
name="firstName"
render={({ field /* { name, value, onChange, onBlur } */ }) => (
<input {...field} type="text" placeholder="firstName" />
)}
/>
// Renders an HTML <input> and disables it while form is submitting
<Field
name="lastName"
render={({ field, form: { isSubmitting } }) => (
<input {...field} disabled={isSubmitting} type="text" placeholder="lastName" />
)}
/>
// Renders an HTML <input> with custom error <div> element
<Field
name="lastName"
render={({ field, form: { touched, errors } }) => (
<div>
<input {...field} type="text" placeholder="lastName" />
{touched[field.name] &&
errors[field.name] && <div className="error">{errors[field.name]}</div>}
</div>
)}
/>
I like defining the form level validation using Yup. But then, i also want to be able to validate specific fields. Is there no way i can do that?
🐛 Bug report
I am trying to use validateField function however I got an error. I am just trying to use the basic example provided by Formik web site.
My code is
import React from 'react'; import { Formik } from 'formik'; const Basic = () => (
);
export default Basic;
Current Behavior
When pressing on click, I got the following Error
react-dom.development.js:57 Uncaught Invariant Violation: Objects are not valid as a React child (found: TypeError: Cannot read property 'props' of undefined). If you meant to render a collection of children, use an array instead. in form (at Form.jsx:38) in Formik (at Form.jsx:7) in div (at Form.jsx:5) in Basic (at App.js:18) in Provider (at App.js:17) in App (at src/index.js:42) in ApolloProvider (at src/index.js:41) at invariant (http://localhost:3001/static/js/0.chunk.js:25383:19) at throwOnInvalidObjectType (http://localhost:3001/static/js/0.chunk.js:37612:9) at updateSlot (http://localhost:3001/static/js/0.chunk.js:37898:11) at reconcileChildrenArray (http://localhost:3001/static/js/0.chunk.js:38036:26) at reconcileChildFibers (http://localhost:3001/static/js/0.chunk.js:38435:18) at reconcileChildren (http://localhost:3001/static/js/0.chunk.js:40294:32) at updateHostComponent (http://localhost:3001/static/js/0.chunk.js:40771:7) at beginWork (http://localhost:3001/static/js/0.chunk.js:41595:18) at performUnitOfWork (http://localhost:3001/static/js/0.chunk.js:45605:16) at workLoop (http://localhost:3001/static/js/0.chunk.js:45646:28) at HTMLUnknownElement.callCallback (http://localhost:3001/static/js/0.chunk.js:25473:18) at Object.invokeGuardedCallbackDev (http://localhost:3001/static/js/0.chunk.js:25522:20) at invokeGuardedCallback (http://localhost:3001/static/js/0.chunk.js:25576:35) at replayUnitOfWork (http://localhost:3001/static/js/0.chunk.js:44829:9) at renderRoot (http://localhost:3001/static/js/0.chunk.js:45759:17) at performWorkOnRoot (http://localhost:3001/static/js/0.chunk.js:46683:11) at performWork (http://localhost:3001/static/js/0.chunk.js:46593:11) at performSyncWork (http://localhost:3001/static/js/0.chunk.js:46567:7) at requestWork (http://localhost:3001/static/js/0.chunk.js:46422:9) at scheduleWork (http://localhost:3001/static/js/0.chunk.js:46235:9) at Object.enqueueSetState (http://localhost:3001/static/js/0.chunk.js:36921:9) at Formik.push../node_modules/react/cjs/react.development.js.Component.setState (http://localhost:3001/static/js/0.chunk.js:52349:20) at http://localhost:3001/static/js/0.chunk.js:10861:17
Expected behavior
I expect to check the validation of the email Input field