yup 유효성 검사 스키마를 구현하려고하는데 5 개의 숫자 값 (A, B, C, D, E)이 있다고 가정하겠습니다.
나는 D와 E가 A, B, C 및 일부 상수 값을 기반으로 한 수학 함수보다 작기를 원합니다. 이 같은:
const upperBound = Math.min(A,B,C)-10;
if((D > upperBound) || (E > upperBound))
return FAIL;
else
return PASS;
나는 많은 스레드를 검토했지만 그중 어느 것도 다중 변수 종속성을 해결하지 못했습니다. 감사.
테스트 기능을 사용하여 다음을 수행 할 수 있습니다.
Yup.object().test({
name: 'D and E less than ABC', // Your custom error id
test: function () {
const {A,B,C,D,E} = this.parent; // Access the object data, here this.parent contains your data
const upperBound = Math.min(A,B,C)-10;
if((D > upperBound) || (E > upperBound))
return this.createError({
message: `D and E must be below min`, // Error message for the user
path: `D`, // The object path where you want show the error
});
return true; // True for no error
}),
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다