[英]Issue with ember-cp-validation in an ember-engines
As the title say, I have an issue with ember-cp-validations which I think is related to ember-engines . 如标题所述,我认为ember-cp-validations存在问题 ,我认为这与ember-engines有关 。
Basically, my issue is that there is no validations in a form for a model that use ember-cp-validations. 基本上,我的问题是没有使用ember-cp-validations的模型形式的验证。 Here is my model:
这是我的模型:
import Ember from 'ember';
import DS from 'ember-data';
import { validator , buildValidations } from 'ember-cp-validations';
const Validations = buildValidations(
{
name:[
validator('presence', true),
validator('ds-error'),
validator('length', {
min: 3,
max: 15,
message: 'The length must be between 3-15 character'
})
]
);
export default DS.Model.extend(Validations, {
numericId: Ember.computed('id', function ()
{
"use strict";
return Number(this.get('id'));
}),
name: DS.attr('string'),
});
As you can see, my model is quite simple, and it work perfectly fine in my application. 如您所见,我的模型非常简单,并且在我的应用程序中工作得很好。
For the templates, I am using ember-bootstrap , and it look like that: 对于模板,我正在使用ember-bootstrap ,它看起来像这样:
{{#bs-form formLayout="horizontal" model=myModel onSubmit=(action 'update') as |form|}}
<fieldset>
<legend>Configuration</legend>
{{form.element controlType="text" label=Name
placeholder=myName
property="name"}}
{{bs-button
defaultText=Submit
type="primary"
disabled=(v-get myModel 'isInvalid')
buttonType="submit"}}
</fieldset>
{{/bs-form}}
My template is very simple too, you can see that in the first part of my form I am calling the property="name"
, which is where I am defining the anme property of my model. 我的模板也非常简单,您可以看到在表单的第一部分中,我正在调用
property="name"
,这是我定义模型的anme属性的地方。
The message doesn't show up if my name.length is less than 3 characters for example. 例如,如果我的name.length少于3个字符,则不会显示该消息。
I am in the obligation of adding disabled=(v-get myModel 'isInvalid')
, which will disabled my button if there the validation are not fulfilled, because if I didn't added this property, the information will be sent even if some information where false. 我有义务添加
disabled=(v-get myModel 'isInvalid')
,如果没有完成验证,这将禁用我的按钮,因为如果我没有添加此属性,即使某些信息也会被发送信息在哪里。
Maybe somebody has a tip to make the validation work in my form. 也许有人提示您以我的形式进行验证。 Good day to all of you!
祝大家好!
我刚刚发现它,有一个插件可以自动显示消息错误并以ember-bootstrap形式对其进行验证 : ember-bootstrap-cp-validations
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.