0
我正在尝试使用ember-cp-validations添加表单验证,并按照其控制台中的videoTypeError: user is null
中的基本步骤进行操作。我非常new emb,我相信它很基本,我忽略了。尝试使用ember-cp验证验证表单时出现'TypeError:user is null'
寄存器形成分
import Ember from 'ember';
export default Ember.Component.extend({
user: null,
actions: {
save() {
let user = this.get('user');
user.validate()
.then(({ validations }) => {
if (validations.get('isValid')) {
user.save();
} else {
alert("not valid");
}
});
}
}
});
用户模型
import DS from 'ember-data';
import { validator, buildValidations } from 'ember-cp-validations';
const Validations = buildValidations({
firstname: validator('presence', true),
email: [
validator('presence', true),
validator('format', { type: 'email' })
],
username: validator('presence', true),
password: [
validator('presence', true),
validator('length', {
min: 4
})
]
});
export default DS.Model.extend(Validations, {
firstname: DS.attr('string'),
email: DS.attr('string'),
username: DS.attr('stirng'),
password: DS.attr('string')
});
您将用户设置为空。你如何将用户传递给组件? –