yup

React formik form validation: How to initially have submit button disabled

夙愿已清 提交于 2020-08-01 12:41:21
问题 Below is my React form validation code in which I am using formik . By default when the form loads, I want to keep the submit button disabled: import { useFormik } from "formik"; import * as Yup from "yup"; const formik = useFormik({ initialValues: { firstName: "", lastName: "", email: "" }, validationSchema: Yup.object({ firstName: Yup.string() .max(15, "Must be 15 characters or less") .min(3, "Must be at least 3 characters") .required("Required"), lastName: Yup.string() .min(3, "Must be at

React formik form validation: How to initially have submit button disabled

不羁的心 提交于 2020-08-01 12:40:35
问题 Below is my React form validation code in which I am using formik . By default when the form loads, I want to keep the submit button disabled: import { useFormik } from "formik"; import * as Yup from "yup"; const formik = useFormik({ initialValues: { firstName: "", lastName: "", email: "" }, validationSchema: Yup.object({ firstName: Yup.string() .max(15, "Must be 15 characters or less") .min(3, "Must be at least 3 characters") .required("Required"), lastName: Yup.string() .min(3, "Must be at

Yup: deep validation in array of objects

我怕爱的太早我们不能终老 提交于 2020-07-19 00:58:04
问题 I have a data structure like this: { "subject": "Ah yeah", "description": "Jeg siger...", "daysOfWeek": [ { "dayOfWeek": "MONDAY", "checked": false }, { "dayOfWeek": "TUESDAY", "checked": false }, { "dayOfWeek": "WEDNESDAY", "checked": true }, { "dayOfWeek": "THURSDAY", "checked": false }, { "dayOfWeek": "FRIDAY", "checked": false }, { "dayOfWeek": "SATURDAY", "checked": true }, { "dayOfWeek": "SUNDAY", "checked": true } ], "uuid": "da8f56a2-625f-400d-800d-c975bead0cff", "taskSchedules": [],

Yup: deep validation in array of objects

て烟熏妆下的殇ゞ 提交于 2020-07-19 00:55:25
问题 I have a data structure like this: { "subject": "Ah yeah", "description": "Jeg siger...", "daysOfWeek": [ { "dayOfWeek": "MONDAY", "checked": false }, { "dayOfWeek": "TUESDAY", "checked": false }, { "dayOfWeek": "WEDNESDAY", "checked": true }, { "dayOfWeek": "THURSDAY", "checked": false }, { "dayOfWeek": "FRIDAY", "checked": false }, { "dayOfWeek": "SATURDAY", "checked": true }, { "dayOfWeek": "SUNDAY", "checked": true } ], "uuid": "da8f56a2-625f-400d-800d-c975bead0cff", "taskSchedules": [],

How to test for uniqueness of value in Yup.array?

假如想象 提交于 2020-06-26 04:12:17
问题 I have form with dynamic amount of inputs (admin email) however checking for uniqueness fails: validationSchema={Yup.object().shape({ adminEmails: Yup.array() .of( Yup.string() .notOneOf(Yup.ref('adminEmails'), 'E-mail is already used') What is best approach here? FYI, as a form helper I use Formik . 回答1: Try this: Yup.addMethod(Yup.array, 'unique', function(message, mapper = a => a) { return this.test('unique', message, function(list) { return list.length === new Set(list.map(mapper)).size;

onChange on TextInput Not Working Inside Formik

邮差的信 提交于 2020-05-21 07:25:07
问题 Generally <TextInput> allows you to type even when you're just specifying a placeholder. However, when using within the Formik form, I am unable to type and validate anything in my form. What am I doing wrong? I have tried onChangeText with setFieldValue and handleChange both. const initialValues: FormValues = { friendEmail: '', }; export const Page: React.FunctionComponent<Props> = ({ toggleShowPage, showPage, }) => { const validationSchema = emailValidationSchema; const getFriendId = React

Unable to Type in <Formik> Field

百般思念 提交于 2020-05-21 01:51:17
问题 interface FormValues { friendEmail: string; } const initialValues: FormValues = { friendEmail: '', }; export const Page: React.FunctionComponent<PageProps> = ({ toggleShowPage, showPage, }) => { const [errorMessage, setErrorMessage] = useState(''); const validationSchema = emailValidationSchema; useEffect(() => { if (showPage) return; initialValues.friendEmail = ''; }, [showPage]); const [ createUserRelationMutation, { data: addingFriendData, loading: addingFriendLoading, error:

Unable to Type in <Formik> Field

孤者浪人 提交于 2020-05-21 01:48:52
问题 interface FormValues { friendEmail: string; } const initialValues: FormValues = { friendEmail: '', }; export const Page: React.FunctionComponent<PageProps> = ({ toggleShowPage, showPage, }) => { const [errorMessage, setErrorMessage] = useState(''); const validationSchema = emailValidationSchema; useEffect(() => { if (showPage) return; initialValues.friendEmail = ''; }, [showPage]); const [ createUserRelationMutation, { data: addingFriendData, loading: addingFriendLoading, error:

Handling errors from api with Formik

拜拜、爱过 提交于 2020-05-11 08:36:00
问题 I am catching errors from api and showing them in form, and that is working fine. But the problem is when I change one field in form all errors disappear. For form I am using Formik and for validation Yup. const handleSubmit = (values, {setSubmitting, setFieldError, setStatus}) => { someApiCall(values) .then( () => { }, (error) => { // example of setting error setFieldError('email', 'email is already used'); }) .finally(() => { setSubmitting(false) }); }; I tried with adding third parametar

Handling errors from api with Formik

人盡茶涼 提交于 2020-05-11 08:33:37
问题 I am catching errors from api and showing them in form, and that is working fine. But the problem is when I change one field in form all errors disappear. For form I am using Formik and for validation Yup. const handleSubmit = (values, {setSubmitting, setFieldError, setStatus}) => { someApiCall(values) .then( () => { }, (error) => { // example of setting error setFieldError('email', 'email is already used'); }) .finally(() => { setSubmitting(false) }); }; I tried with adding third parametar