我有以下组件可以制作表单并使用 formik 进行表单验证,并且有一个使用 react-places-autocomplete 创建的自定义输入字段,用于在表单中输入地址。表单工作正常,但是即使地址字段是必需的,验证也没有显示,当我将其清空时,formik 的错误验证没有显示。
下面是组件的代码:
//FormikErrorLabel component
import React from 'react';
const FormikErrorLabel = ({ error, children, ...props }) => {
return <label {...props}>{children}</label>
}
export default FormikErrorLabel;
//FormikErrorLabel component
import React from 'react';
const FormikInputFeedback = ({ children }) => (
<span className="text-danger">{children}</span>
)
export default FormikInputFeedback;
//FormikPlacesAutoComplete custom input places auto complete component with formik validation
import React, { Component } from "react";
import classnames from "classnames";
import FormikErrorLabel from "./FormikErrorLabel";
import FormikInputFeedback from "./FormikInputFeedback";
import …Run Code Online (Sandbox Code Playgroud)