旧方式:
this.validator = this.validation.on(this)
.ensure('baseContent.RedirectFrom')
.isNotEmpty()
.ensure('baseContent.RedirectTo')
.isNotEmpty()
.isNotEqualTo(() => { return this.baseContent.RedirectFrom }, 'Redirect from');
});
isNotEquals似乎不存在于新验证中有equals(expectedValue)
我考虑过做一个自定义验证元素,但是当它通过' RedirectFrom'如未定义。
ValidationRules.customRule('notEqualTo',
(value, obj, otherValue) => {
return value === null || value === undefined || value === '' || otherValue === null || otherValue === undefined || otherValue === ''|| value === otherValue;
},
"must not match");
.ensure('RedirectTo').required().satisfiesRule('notEqualTo', this.baseContent.RedirectFrom)
.ensure('RedirectTo').required().satisfiesRule('notEqualTo', this.RedirectFrom)
.ensure('RedirectTo').required().satisfiesRule('notEqualTo', RedirectFrom)
任何人都会看到我遗失的任何内容?
答案 0 :(得分:1)
物镜将[PropertyName]
CustomValidation.js
ValidationRules.customRule('mustNotMatchValue',
(value, obj, valueToNotMatch) => {
return value === null || value === undefined || value === '' || obj[valueToNotMatch] === null || obj[valueToNotMatch] === undefined || obj[valueToNotMatch] === '' || value !== obj[valueToNotMatch];
},
"must not match ${$config.valueToNotMatch}",
(valueToNotMatch) => ({ valueToNotMatch }));
baseContent.js
.ensure('RedirectTo').required().satisfiesRule('mustNotMatchValue', 'RedirectFrom');