问题描述
我正在处理多种表格。在某些情况下,表单具有类似的字段,例如姓名、电话号码、帐号等。我也在使用 formik 。我为每个表单创建了架构文件 (schema.js)。在里面,我列出了所有架构验证并返回该架构。
例如:schema.js
const schema = yup.object().shape({
firmName: yup.string().label(Labels.FIRM).max(255)
});
export default schema;
如果我有 10 个表单,其中包含 FirmName 字段,那么我所有的 schema.js 文件都在属性 firmName
之上。
我不知道如何分离它并重新使用它。
如果有人遇到并解决了类似的情况,请告诉我方法。
上述编码方式增加了声纳扫描中的重复百分比。请帮忙
解决方法
我是这样做的:
const password = {
password: yup.string().required().min(8),};
const setupPassword = {
...password,confirmPassword: yup
.string()
.defined(t('password.confirm.required'))
.test('passwords-match',t('password.confirm.match'),function (value) {
return this.parent.password === value;
}),agreeToTerms: yup.boolean().test('is-true',value => value === true),};
export const SchemaPasswordValidation = yup.object().shape({
...setupPassword,});