( /* "handleSubmit" will validate your inputs before invoking "onSubmit" */ <form onSubmit={handleSubmit(onSubmit)}> {/* register your input into the hook by invoking the "register" function */} <input defaultValue="test" {...register("example")} /> {/* include validation with ...
import useForm from '@custom-react-hooks/use-form'; const FormComponent = () => { const initialValues = { username: '', email: '' }; const [submitting, setSubmitting] = useState(false); const [submitResult, setSubmitResult] = useState(''); const validate = (values) => { const ...
validate({ value, field, fields }) where value is the field's value, field is the full field with all properties, and fields is all fields with their properties. Returns an object with the following properties: isValid: <Boolean>, // Whether the field is valid. value: <String> or <...
首先是在校验层面,之前用的 iview 组件库,Form 把整体属性绑定在一起,分拆较为麻烦,推荐 vee-validate,可以较为优雅的把表单分拆,并可以很方便的合并处理(另外该库作者也正在使用3.0重写该库)。其次,遇到联动情况的组件/业务模块分拆逻辑需要提前设计好,主要是注意 watch 的设计,composition function 的调用关系,以及...