我使用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被隱藏後驗證不起作用,然後再次顯示。