提交表单后清除formik错误

问题描述

当我进入屏幕时,在输入字段上没有显示任何错误。在我的Formik表单中,我接受输入并对其运行graphql突变。完成后,我将重置表单。但是,重置后,我开始看到Formik错误,因为该字段为 .required(),并且当前为空。

仅当我尝试不输入任何内容提交表单时,才应显示错误。成功提交后,它应该不会显示

  const handleSubmitForm = (
    values: FormValues,helpers: FormikHelpers<FormValues>,) => {
    editLocationName({
      variables: {
      favouritePlaceId: route.params.id,input: {customisedname: values.locationName}
      },});
    helpers.resetForm();
    helpers.setErrors({});
  };
.....


          <Formik
            initialValues={initialValues}
            onSubmit={handleSubmitForm}
            validationSchema={validationSchema}>
            {({ handleChange,handleBlur,handleSubmit,values }) => (
              <View style={styles.searchFieldContainer}>
                <View style={styles.form}>
                  <FieldInput
                    handleChange={handleChange}
                    handleBlur={handleBlur}
                    value={values.locationName}
                    fieldType="locationName"
                    placeholderText="Neuer Name"
                  />
                  <ErrorMessage
                    name="locationName"
                    render={(msg) => <ErrorText errorMessage={msg} />}
                  />
                </View>
                <View style={styles.buttonContainer}>
                  <ActionButton buttonText="Save" onPress={handleSubmit} />
                </View>
              </View>
            )}
          </Formik>

验证模式:

const favouriteLocationNameValidationSchema = yup.object().shape({
  locationName: yup
  .string()
  .label('locationName')
  .required('required Field')
  .max(70,'Too Long!')
  .min(3,'Too Short!'),});

如何清除/重置错误以及表格?

setErrors在这里没有任何区别。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)