2016-11-28 39 views
1

老辦法:新Aurelia驗證!等於(expectedValue)

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) 

任何人都能看到我失蹤的任何東西?

回答

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');