Formik | How to user Multiple validation schemas and render Split Views for a formDjango: form validation: accepting multiple values for one fieldValidation on my HTML form in Javascript?When editing an existing document in React, Meteor Simple Schema validation on client side always returns 'true', despite invalid form dataHow to validate collections (list must not be empty rules) in Angular 2 Forms?Sending data from a form to the parent component in ReactJSAngular 2 requiring one of two items in a formgroupHow to use Redux and Axios in React JS?Formik validation not working for my custom react-places-autocomplete componentHow to show error only if Field is touched? | React && FormikRendering Formik Field outside Formik form
Why, even after his imprisonment, do people keep calling Hannibal Lecter "Doctor"?
What should I consider when deciding whether to delay an exam?
Convert a string of digits from words to an integer
Vilna Gaon's gematria for the number of kosher & non-kosher sukkot in Masechet Sukkah
How many stack cables would be needed if we want to stack two 3850 switches
How deep is the liquid in a half-full hemisphere?
Avoiding dust scattering when you drill
Is there a relationship between prime numbers and music?
Can RPi4 run simultaneously on dual band (WiFi 2.4GHz / 5GHz)?
To what degree did the Supreme Court limit Boris Johnson's ability to prorogue?
What are examples of EU policies that are beneficial for one EU country, disadvantagious for another?
Lost passport and visa, tried to reapply, got rejected twice. What are my next steps?
Beyond Futuristic Technology for an Alien Warship?
How important is knowledge of trig identities for use in Calculus
If a spaceship ran out of fuel somewhere in space between Earth and Mars, does it slowly drift off to the Sun?
Create the same subfolders in another folder
Why does `FindFit` fail so badly in this simple case?
How do we know neutrons have no charge?
Smallest PRIME containing the first 11 primes as sub-strings
How to stop the death waves in my city?
How to study endgames?
Why most footers have a background color has a divider of section?
How do my husband and I get over our fear of having another difficult baby?
Is there an in-universe explanation of how Frodo's arrival in Valinor was recorded in the Red Book?
Formik | How to user Multiple validation schemas and render Split Views for a form
Django: form validation: accepting multiple values for one fieldValidation on my HTML form in Javascript?When editing an existing document in React, Meteor Simple Schema validation on client side always returns 'true', despite invalid form dataHow to validate collections (list must not be empty rules) in Angular 2 Forms?Sending data from a form to the parent component in ReactJSAngular 2 requiring one of two items in a formgroupHow to use Redux and Axios in React JS?Formik validation not working for my custom react-places-autocomplete componentHow to show error only if Field is touched? | React && FormikRendering Formik Field outside Formik form
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I understand this may be an unothodox question, or even 2 in one, but
please believe me when I say thiese 2 cannot be answered seperately.
Please keep that in mind. Thank you for your time..
My question revolves around a particular scenario I am currently facing. I am using the withFormik H.O.C, along with Yup, to handle various cases in my forms, such as submitting, errorHandling, and a few more depending on the situation.
Usually, my form situation involves a Create and an Edit Mode.
onCreate => Pass the defaultvalues and call the POST Method, from my services.
onEdit => Populate the values with the current Item Values from the Server, and call the PUT Method from the services.
Example
const validationSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
password: Yup.string('Provide a Password').required('Password is required'),
confirmPassword: Yup.string('Provide your password again')
.required('Password Confirmation is Required')
.oneOf([Yup.ref('password')], 'Passwords do not match'),
);
const EnchancedCreateUserForm = withFormik(
mapPropsToValues: (
user =
username: '',
email: '',
password: '',
confirmPassword: '',
) => ( ...user ),
validationSchema,
handleSubmit: (values, props, setSubmitting ) =>
const doSubmit, onSave, inEditMode = props;
const saveUser = inEditMode ? updateUser : createUser;
return doSubmit(saveUser, values)
.then(() =>
setSubmitting(false);
onSave();
)
.catch(() =>
setSubmitting(false);
);
,
displayName: 'AddEditUser'
)(AddEditUser);
That is actually been working great for me, since my Create and Edit Form are the same. And here lay my 2 problems.
Current Situation
My current form implementation has 2 views. One unified one on Create with those 4 fields, and on Edit, I have 2 forms. One for passwordChange and one for infoChange. Which makes me face the following problems.
I would need 3 FormValidationSchemas(CREATE, EDIT-INFO, EDIT-PASSWORD). Which I am not sure formik even supports.
How exactly, should I handle the rest of the functionality, onSubmit, ErrorMessage for both field error and statusError?
If you could actually help me out figure a way of attack it would be great.
I read the validationSchema can be passed a function that returns a validationSchema, so I did this, but it is not working:
const validationFullSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
password: Yup.string('Provide a Password').required('Password is required'),
confirmPassword: Yup.string('Provide your password again')
.required('Password Confirmation is Required')
.oneOf([Yup.ref('password')], 'Passwords do not match'),
);
const validationEditSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
);
const validationSchemaFn = () =>
If ( efitMode )
return validationCreateSchema
return validationEditSchema
validationSchema: validationSchemaFn(),
// Which throws an error
// Failed to load app. Error: Cannot read property 'props' of undefined
I probably am doing something wrong, but I put it here just in case.
My Opinion on the matter
- Create 2 Form Components(PasswordFormComponent, InfoFormComponent), and wrap each one with the H.O.C, allowing them access to the withFormik independantly.
- For CreateForm, convert it into a container Component, that renders both of those components
- For Edit instead of calling the whole form, which is currently what is happening, call for each situation the specific component.
What do you of my proposed solution? If you like it, could you please make it better or help with some code samples, especially in the multiple validationSchemas issues. Thank you!!
javascript reactjs forms typescript formik
add a comment
|
I understand this may be an unothodox question, or even 2 in one, but
please believe me when I say thiese 2 cannot be answered seperately.
Please keep that in mind. Thank you for your time..
My question revolves around a particular scenario I am currently facing. I am using the withFormik H.O.C, along with Yup, to handle various cases in my forms, such as submitting, errorHandling, and a few more depending on the situation.
Usually, my form situation involves a Create and an Edit Mode.
onCreate => Pass the defaultvalues and call the POST Method, from my services.
onEdit => Populate the values with the current Item Values from the Server, and call the PUT Method from the services.
Example
const validationSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
password: Yup.string('Provide a Password').required('Password is required'),
confirmPassword: Yup.string('Provide your password again')
.required('Password Confirmation is Required')
.oneOf([Yup.ref('password')], 'Passwords do not match'),
);
const EnchancedCreateUserForm = withFormik(
mapPropsToValues: (
user =
username: '',
email: '',
password: '',
confirmPassword: '',
) => ( ...user ),
validationSchema,
handleSubmit: (values, props, setSubmitting ) =>
const doSubmit, onSave, inEditMode = props;
const saveUser = inEditMode ? updateUser : createUser;
return doSubmit(saveUser, values)
.then(() =>
setSubmitting(false);
onSave();
)
.catch(() =>
setSubmitting(false);
);
,
displayName: 'AddEditUser'
)(AddEditUser);
That is actually been working great for me, since my Create and Edit Form are the same. And here lay my 2 problems.
Current Situation
My current form implementation has 2 views. One unified one on Create with those 4 fields, and on Edit, I have 2 forms. One for passwordChange and one for infoChange. Which makes me face the following problems.
I would need 3 FormValidationSchemas(CREATE, EDIT-INFO, EDIT-PASSWORD). Which I am not sure formik even supports.
How exactly, should I handle the rest of the functionality, onSubmit, ErrorMessage for both field error and statusError?
If you could actually help me out figure a way of attack it would be great.
I read the validationSchema can be passed a function that returns a validationSchema, so I did this, but it is not working:
const validationFullSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
password: Yup.string('Provide a Password').required('Password is required'),
confirmPassword: Yup.string('Provide your password again')
.required('Password Confirmation is Required')
.oneOf([Yup.ref('password')], 'Passwords do not match'),
);
const validationEditSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
);
const validationSchemaFn = () =>
If ( efitMode )
return validationCreateSchema
return validationEditSchema
validationSchema: validationSchemaFn(),
// Which throws an error
// Failed to load app. Error: Cannot read property 'props' of undefined
I probably am doing something wrong, but I put it here just in case.
My Opinion on the matter
- Create 2 Form Components(PasswordFormComponent, InfoFormComponent), and wrap each one with the H.O.C, allowing them access to the withFormik independantly.
- For CreateForm, convert it into a container Component, that renders both of those components
- For Edit instead of calling the whole form, which is currently what is happening, call for each situation the specific component.
What do you of my proposed solution? If you like it, could you please make it better or help with some code samples, especially in the multiple validationSchemas issues. Thank you!!
javascript reactjs forms typescript formik
add a comment
|
I understand this may be an unothodox question, or even 2 in one, but
please believe me when I say thiese 2 cannot be answered seperately.
Please keep that in mind. Thank you for your time..
My question revolves around a particular scenario I am currently facing. I am using the withFormik H.O.C, along with Yup, to handle various cases in my forms, such as submitting, errorHandling, and a few more depending on the situation.
Usually, my form situation involves a Create and an Edit Mode.
onCreate => Pass the defaultvalues and call the POST Method, from my services.
onEdit => Populate the values with the current Item Values from the Server, and call the PUT Method from the services.
Example
const validationSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
password: Yup.string('Provide a Password').required('Password is required'),
confirmPassword: Yup.string('Provide your password again')
.required('Password Confirmation is Required')
.oneOf([Yup.ref('password')], 'Passwords do not match'),
);
const EnchancedCreateUserForm = withFormik(
mapPropsToValues: (
user =
username: '',
email: '',
password: '',
confirmPassword: '',
) => ( ...user ),
validationSchema,
handleSubmit: (values, props, setSubmitting ) =>
const doSubmit, onSave, inEditMode = props;
const saveUser = inEditMode ? updateUser : createUser;
return doSubmit(saveUser, values)
.then(() =>
setSubmitting(false);
onSave();
)
.catch(() =>
setSubmitting(false);
);
,
displayName: 'AddEditUser'
)(AddEditUser);
That is actually been working great for me, since my Create and Edit Form are the same. And here lay my 2 problems.
Current Situation
My current form implementation has 2 views. One unified one on Create with those 4 fields, and on Edit, I have 2 forms. One for passwordChange and one for infoChange. Which makes me face the following problems.
I would need 3 FormValidationSchemas(CREATE, EDIT-INFO, EDIT-PASSWORD). Which I am not sure formik even supports.
How exactly, should I handle the rest of the functionality, onSubmit, ErrorMessage for both field error and statusError?
If you could actually help me out figure a way of attack it would be great.
I read the validationSchema can be passed a function that returns a validationSchema, so I did this, but it is not working:
const validationFullSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
password: Yup.string('Provide a Password').required('Password is required'),
confirmPassword: Yup.string('Provide your password again')
.required('Password Confirmation is Required')
.oneOf([Yup.ref('password')], 'Passwords do not match'),
);
const validationEditSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
);
const validationSchemaFn = () =>
If ( efitMode )
return validationCreateSchema
return validationEditSchema
validationSchema: validationSchemaFn(),
// Which throws an error
// Failed to load app. Error: Cannot read property 'props' of undefined
I probably am doing something wrong, but I put it here just in case.
My Opinion on the matter
- Create 2 Form Components(PasswordFormComponent, InfoFormComponent), and wrap each one with the H.O.C, allowing them access to the withFormik independantly.
- For CreateForm, convert it into a container Component, that renders both of those components
- For Edit instead of calling the whole form, which is currently what is happening, call for each situation the specific component.
What do you of my proposed solution? If you like it, could you please make it better or help with some code samples, especially in the multiple validationSchemas issues. Thank you!!
javascript reactjs forms typescript formik
I understand this may be an unothodox question, or even 2 in one, but
please believe me when I say thiese 2 cannot be answered seperately.
Please keep that in mind. Thank you for your time..
My question revolves around a particular scenario I am currently facing. I am using the withFormik H.O.C, along with Yup, to handle various cases in my forms, such as submitting, errorHandling, and a few more depending on the situation.
Usually, my form situation involves a Create and an Edit Mode.
onCreate => Pass the defaultvalues and call the POST Method, from my services.
onEdit => Populate the values with the current Item Values from the Server, and call the PUT Method from the services.
Example
const validationSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
password: Yup.string('Provide a Password').required('Password is required'),
confirmPassword: Yup.string('Provide your password again')
.required('Password Confirmation is Required')
.oneOf([Yup.ref('password')], 'Passwords do not match'),
);
const EnchancedCreateUserForm = withFormik(
mapPropsToValues: (
user =
username: '',
email: '',
password: '',
confirmPassword: '',
) => ( ...user ),
validationSchema,
handleSubmit: (values, props, setSubmitting ) =>
const doSubmit, onSave, inEditMode = props;
const saveUser = inEditMode ? updateUser : createUser;
return doSubmit(saveUser, values)
.then(() =>
setSubmitting(false);
onSave();
)
.catch(() =>
setSubmitting(false);
);
,
displayName: 'AddEditUser'
)(AddEditUser);
That is actually been working great for me, since my Create and Edit Form are the same. And here lay my 2 problems.
Current Situation
My current form implementation has 2 views. One unified one on Create with those 4 fields, and on Edit, I have 2 forms. One for passwordChange and one for infoChange. Which makes me face the following problems.
I would need 3 FormValidationSchemas(CREATE, EDIT-INFO, EDIT-PASSWORD). Which I am not sure formik even supports.
How exactly, should I handle the rest of the functionality, onSubmit, ErrorMessage for both field error and statusError?
If you could actually help me out figure a way of attack it would be great.
I read the validationSchema can be passed a function that returns a validationSchema, so I did this, but it is not working:
const validationFullSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
password: Yup.string('Provide a Password').required('Password is required'),
confirmPassword: Yup.string('Provide your password again')
.required('Password Confirmation is Required')
.oneOf([Yup.ref('password')], 'Passwords do not match'),
);
const validationEditSchema = Yup.object().shape(
username: Yup.string('Provide a Username').required('Username is Required'),
email: Yup.string().email('Provide a Valid email Address'),
);
const validationSchemaFn = () =>
If ( efitMode )
return validationCreateSchema
return validationEditSchema
validationSchema: validationSchemaFn(),
// Which throws an error
// Failed to load app. Error: Cannot read property 'props' of undefined
I probably am doing something wrong, but I put it here just in case.
My Opinion on the matter
- Create 2 Form Components(PasswordFormComponent, InfoFormComponent), and wrap each one with the H.O.C, allowing them access to the withFormik independantly.
- For CreateForm, convert it into a container Component, that renders both of those components
- For Edit instead of calling the whole form, which is currently what is happening, call for each situation the specific component.
What do you of my proposed solution? If you like it, could you please make it better or help with some code samples, especially in the multiple validationSchemas issues. Thank you!!
javascript reactjs forms typescript formik
javascript reactjs forms typescript formik
edited Mar 29 at 7:16
Dimitris Efst
asked Mar 28 at 19:54
Dimitris EfstDimitris Efst
4223 silver badges19 bronze badges
4223 silver badges19 bronze badges
add a comment
|
add a comment
|
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405881%2fformik-how-to-user-multiple-validation-schemas-and-render-split-views-for-a-fo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405881%2fformik-how-to-user-multiple-validation-schemas-and-render-split-views-for-a-fo%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown