gpt4 book ai didi

javascript - 如何重用 Yup 验证模式 + 声纳扫描在 yup 模式验证文件上显示更多重复,它增加了重复覆盖率

转载 作者:行者123 更新时间:2023-12-05 01:07:29 25 4
gpt4 key购买 nike

我正在处理多种表单。在某些情况下,表格具有相似的字段,例如姓名、电话号码、帐号等。我也在使用 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,
});

关于javascript - 如何重用 Yup 验证模式 + 声纳扫描在 yup 模式验证文件上显示更多重复,它增加了重复覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67413574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com