我有一个运行许多验证的模式。但是我不想在出现错误的情况下显示一些错误消息,尽管我希望突出显示该字段。给出空字符串而不是错误消息会导致 formik 不显示红色输入字段但验证运行。这是我当前的代码
const LocationDetailsSchema = Yup.object().shape({
location: Yup.string(),
locationCategory: Yup.string(),
lat: Yup.number()
.min(-85, "Not a valid Latitude")
.max(85, "Not a valid Latitude")
.nullable()
.transform(function(value) {
return this.isType(value) ? value : null;
})
.test(
"match",
"", //empty string fails, putting a text shows but i don't want the text to appear
function(){
if (principalAmount>=500000) return true;
return false;
}
),
lon: Yup.number()
.min(-180, "Not a valid Longitude")
.max(180, "Not a valid Longitude")
.nullable()
.transform(function(value) {
return this.isType(value) ? value : null;
})
.test(
"match",
"Is valid", // this works but i don't want the text to appear either
function(){
if (principalAmount>=500000) return true;
return false;
}
),
});