驗證應該發送給控制器,除非您使用可複製的dyanmic formset。此外u必須包裝ControllerObject這個
VAR AddController = Ember.ArrayController.extend(Ember.Validations.Mixin,{}
要啓動驗證u必須使名爲驗證新的對象
您必須添加的輸入值進行驗證
validations: {
newFirstname:{
format: { with: /^[A-Za-z-]{2,16}$/, allowBlank: true, message: 'Enter valid name.' }
},
newFamilyname: {
format: { with: /^[A-Za-z-]{3,16}$/ , message: 'Required field lastname.' }
}
},
顯示錯誤。
<div class="row">
<div class="col-md-6 col-xs-4">
<label>First name: </label>
{{input type="text" placeholder="First name" value=newFirstname class="form-control"}}
{{#if errors.newFirstname}}
<span class="error errorForValidation"><span class="glyphicon glyphicon-warning-sign"></span> {{errors.newFirstname}}</span>
{{/if}}
</div>
<div class="col-md-6 col-xs-4">
<label>*Last name: </label>
{{input type="text" placeholder="Family name" value=newFamilyname class="form-control"}}
{{#if errors.newFamilyname}}
<span class="error"><span class="glyphicon glyphicon-warning-sign"></span> {{errors.newFamilyname}}</span>
{{/if}}
</div>
</div><!--end row-->
顯示按鈕,當確認是完美無瑕的
<button type="submit" class="btn btn-primary" {{bind-attr disabled="isInvalid"}}{{action 'GetData'}}>Create</button>
JSBIN:本http://emberjs.jsbin.com/iDeQABo/17/edit
的一個問題是,在提交應驗證卻使輸入文本字段不驗證第一和顯示錯誤信息。 –