yup

Conditional validation with Yup and Formik

夙愿已清 提交于 2020-04-11 03:54:52
问题 Here is my validation schema: const validationSchema = Yup.object().shape({ person: Yup.object().shape({ name: Yup.string().required('Field is required'), surname: Yup.string().required('Field is required'), middleName: Yup.string().required('Field is required'), email: Yup.string() .email('Wrong e-mail format') .required('Field is required') }), company: Yup.object().shape({ name: Yup.string().required('Field is required'), address: Yup.string().required('Field is required'), email: Yup

Conditional validation with Yup and Formik

这一生的挚爱 提交于 2020-04-11 03:53:48
问题 Here is my validation schema: const validationSchema = Yup.object().shape({ person: Yup.object().shape({ name: Yup.string().required('Field is required'), surname: Yup.string().required('Field is required'), middleName: Yup.string().required('Field is required'), email: Yup.string() .email('Wrong e-mail format') .required('Field is required') }), company: Yup.object().shape({ name: Yup.string().required('Field is required'), address: Yup.string().required('Field is required'), email: Yup

How do you Create a Formik YUP Schema with Dynamic Field Names?

隐身守侯 提交于 2020-03-25 13:47:12
问题 How do you create a YUP schema with dynamic dot notation field names? The below schema is not valid. How would I iterate through Costs.0.item, Costs.1.item, Costs.2.item AND Costs.0.amount, Costs.1.amount, Costs.2.amount dynamically? Any help is appreciated! const IpSchema = Yup.object().shape({ Project_Title: Yup.string() .min(2, 'Too Short!') .max(255, 'Too Long!') .required('Required'), Costs.0.item: Yup.string() .min(2, 'Too Short!') .max(255, 'Too Long!') .required('Required'), Costs.1

How do I validate if a start date is after an end date with Yup?

混江龙づ霸主 提交于 2020-03-23 07:48:39
问题 I have a form that creates an event using Formik library. I need to check to see if the start date overlaps the end date and vice-versa. I have two date pickers that choose the date and time. How can I use Yup to validate this and show an error message if they do overlap? Thanks for the help in advance const validationSchema = Yup.object().shape({ eventName: Yup.string() .min(1, "Must have a character") .max(10, "Must be shorter than 255") .required("Must enter an event name"), email: Yup

how to pass a child component's validated data (as a formik form) to its parent component and handle form submission in parent

本小妞迷上赌 提交于 2019-12-31 06:54:39
问题 Is there a way to pass formik form values from a child component to a parent component and handle form submission in parent component only. I have a use case where I'm building a form for restaurant. The form will have many many fields. So I grouped them and created seperate smaller formik forms component. All the child components' validation schema (yup) are written there inside the child component. Or if there is any another method to accomplish this task, please let me know. class

How to set and get a datepicker value using antd with formik?

一笑奈何 提交于 2019-12-24 00:38:27
问题 Here i am creating Datepicker with antd and passing this antd datepicker to formik field.My sample code for Datepicker with antd import React from "react"; import { Form, DatePicker } from "antd" import { Field } from "formik"; import moment from 'moment'; const FormItem = Form.Item; function onChange(date, dateString) { console.log(date, dateString); } const dateFormat = "MM-DD-YYYY" // Here i am adding antd error message through DateInput const DateInput = ({ field, form: { touched, errors

How to Validate Multiple Phone Numbers with Formik Yup

谁说我不能喝 提交于 2019-12-13 03:46:33
问题 I am building a form a where a user can store multiple phone numbers and set the privacy of that number (whether he wants the number to be publicly displayed or not). I have succesfully created the form but stuck in formik-yup validation and getting the values (phone number with privacy value) to further send it to backend. import React, { Component } from "react"; import { Formik, Form, Field, ErrorMessage, FieldArray } from "formik"; import * as Yup from "yup"; import DropDown from ".

How to reset antd datepicker after submiting a value?

房东的猫 提交于 2019-12-11 18:43:16
问题 here i am providing my sample example working on codesandbox. How to reset a datepicker value after submitting a form? state = { setFieldValue: '' } onChange = (setFieldValue) => { this.setState({ setFieldValue: null }) } render() { const { values, handleSubmit } = this.props return ( <div align="center"> <Form onSubmit={handleSubmit}> <Field name="dateofbirth" label="dateOfBirth" component={DateInput} formitemlayout={formItemLayout} value={this.state.setFieldValue} onChange={this.onChange} /

Formik + Yup don't validate input if untouched

∥☆過路亽.° 提交于 2019-12-11 16:11:48
问题 I am trying to use Formik + Yup to validate my form, but currently if I touch one field, and then try and submit, a field that has a minimum length will validate, and not allow me to submit. Following my code sandbox (https://codesandbox.io/s/focused-bardeen-5fiuz), I want the user to be able to submit the form if they just change the firstName field, but without entering anything for the country field. I tried both the .notRequired() and .nullable(true) params, but did not work. Any idea how

How to execute custom function once the field is valid with Formikl / Yup

无人久伴 提交于 2019-12-11 15:42:14
问题 I want execute a custom function when the field become valid? Something like this.. <Field name="postal-code" onValid={...} /> The reason is that I want make fetch (GET) to get address from API once the user type an valid Postal code 回答1: You can define the custom function inside the component class or outside the component. // outside the component (best suited for functional component) const onValidFn = () => { // perform action } // inside the component (best suited for stateful component)