在aurelia-validation版本0.6.8中,您可以使用isValid标志检查html中的验证是否已通过或失败。
像这样设置验证属性:
import {Validation} from 'aurelia-validation'; @inject(Validation) @customElement('base-content') export class BaseContent { this.validation = validation; this.validator = this.validation.on(this).ensure('baseContent.Name').isNotEmpty(); }然后像这样使用isValid:
<button class="btn btn-success" type="submit" disabled.bind="!validation.result.isValid">Sign In</button>这曾经工作,但我最近升级了aurelia验证,所以我现在有以下包。 - aurelia-validation@0.9.2 - aurelia-validatejs@0.5.2
我正在寻找的是一种复制我以前做过的方法,但是使用新的包。 这是我能得到的最接近但是我不想在以前有一个不错的选择时进行脏检查。
import {inject, NewInstance} from 'aurelia-framework'; @inject(NewInstance.of(ValidationController)) export class Login { this.controller = controller; } get isValid(){ if (this.controller.validate().length == 0) { return true; } return false; }<button class="btn btn-success" type="submit" disabled.bind="!.isValid">Sign In</button>有任何想法吗?
In aurelia-validation version 0.6.8 you could check if the validation had passed or failed in the html using the isValid flag.
Set up the validation property like this:
import {Validation} from 'aurelia-validation'; @inject(Validation) @customElement('base-content') export class BaseContent { this.validation = validation; this.validator = this.validation.on(this).ensure('baseContent.Name').isNotEmpty(); }And then use the isValid like this:
<button class="btn btn-success" type="submit" disabled.bind="!validation.result.isValid">Sign In</button>That used to work but I have recently upgraded the aurelia validation so I now have the following packages. - aurelia-validation@0.9.2 - aurelia-validatejs@0.5.2
What I'm looking for is a way to replicate what I used to do but with the new packages. This is the closest I could get but I don't want to be dirty checking when there used to be a nice alternative.
import {inject, NewInstance} from 'aurelia-framework'; @inject(NewInstance.of(ValidationController)) export class Login { this.controller = controller; } get isValid(){ if (this.controller.validate().length == 0) { return true; } return false; }<button class="btn btn-success" type="submit" disabled.bind="!.isValid">Sign In</button>Any ideas?
最满意答案
您可以使用validation-errors自定义属性来获取对当前errors数组的引用。 此数组中的对象形状如下: { error: ValidationError, target: Element } 。
<form validation-errors.bind="errors"> ... ... <button class="btn btn-success" type="submit" disabled.bind="errors.length">Sign In</button> </form>You could use the validation-errors custom attribute to get a reference to the current errors array. Objects in this array are shaped like this: { error: ValidationError, target: Element }.
<form validation-errors.bind="errors"> ... ... <button class="btn btn-success" type="submit" disabled.bind="errors.length">Sign In</button> </form>
更多推荐
发布评论