[英]How to implement form validation in ember-cli app?
I am developing a Ember-CLI app. 我正在开发一个Ember-CLI应用程序。 I have installed
我已经安装
The form is generated properly. 该表格生成正确。 But the validations are not triggered.
但是不会触发验证。
{{#em-form model=controller class="col-md-5"}}
{{em-input property="title" label="Title" placeholder="Title"}}
{{em-text property="description" label="Description" placeholder="Description"}}
{{/em-form}}
The controller code with validations is 带有验证的控制器代码是
import Ember from "ember";
export default Ember.Controller.extend({
actions: {
submit: function() {
}
},
validations: {
title: {
presence: true,
length: { minimum: 5, maximum: 10 }
}
}
});
Any idea? 任何想法?
According to the docs "You need to mixin EmberValidations.Mixin into any Ember.Object you want to add validations to". 根据文档“您需要将EmberValidations.Mixin混入要向其中添加验证的Ember.Object中”。 It seems something like this would work:
看起来像这样会工作:
import Ember from "ember";
import EmberValidations from 'ember-validations';
export default Ember.Controller.extend(EmberValidations.Mixin, {
actions: {
submit: function() {
}
},
validations: {
title: {
presence: true,
length: { minimum: 5, maximum: 10 }
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.