我使用aurelia-validation插件进行输入验证时遇到问题。if.bind中的Aurelia验证和对象属性不起作用
我想验证的属性绑定是一个对象的属性(有时为null),它位于此对象的if.bind中。
这里是我的代码:
<div class="well" if.bind="selectedBody">
<input type="text" class="input-sm" class="form-control" value.bind="selectedBody.name & validate" required pattern="[a-z]+[aA-zZ|0-9]*">
<ul if.bind="controller.errors">
<li repeat.for="error of controller.errors">
${error.message}
</li>
</ul>
</div>
和我的视图模型构造:
constructor(private ea : EventAggregator, private controllerFactory: ValidationControllerFactory) {
this.controller = controllerFactory.createForCurrentScope();
ValidationRules.ensure('selectedBody.name').required().withMessage("Sprite name is required").on(this);
}
我试图通过更换验证规则:
ValidationRules.ensure('name').required().withMessage("Sprite name is required").on(this.selectedBody);
但后来我需要设置我的对象是一个空对象而不是null,并且在div被隐藏后验证不起作用,然后再次显示。