Hi there!
I'm new to Ember and trying to get up and running with EFM2000 and ember-validations. I've gotten it to work up to a point, but I'm not sure where to go from here. At the moment, my validations work in the front end, which is great. The two problems I have are:
- The new template starts out with validation failed. How do I start with a non-validated object that updates per field as I go along?
- The
has-error class never gets removed, even if validation passes. I had a look and the errors object it's looking at is empty. Why could it be that the class doesn't get removed?
My code is as follows:
//app/controllers/clients/new.js
import Ember from 'ember';
import EmberValidations from 'ember-validations';
export default Ember.Controller.extend(EmberValidations.Mixin, {
validations: {
clientName: {
presence: true,
length: { minimum: 5 }
},
clientEmail: {
presence: true,
length: { minimum: 5 }
}
},
actions: {
saveClient: function(){
var newClient = this.store.createRecord('client', {
clientName: this.get('clientName'),
clientEmail: this.get('clientEmail')
});
newClient.save();
this.setProperties({
clientName: '',
clientEmail: ''
});
}
}
});
//app/templates/clients/new.hbs
{{#fm-form action='saveClient'}}
{{fm-field type='text' value=clientName label='Client Name' errors=controller.errors.clientName}}
{{fm-field type='text' value=clientEmail label='Client Email' errors=controller.errors.clientEmail}}
{{fm-submit value='Save Client'}}
{{/fm-form}}
//app/templates/models/client.js
import DS from 'ember-data';
export default DS.Model.extend({
clientName: DS.attr('string'),
clientEmail: DS.attr('string')
});
As said, I'm super new to Ember so please tell me if I'm being stupid. :)
Hi there!
I'm new to Ember and trying to get up and running with EFM2000 and ember-validations. I've gotten it to work up to a point, but I'm not sure where to go from here. At the moment, my validations work in the front end, which is great. The two problems I have are:
has-errorclass never gets removed, even if validation passes. I had a look and the errors object it's looking at is empty. Why could it be that the class doesn't get removed?My code is as follows:
As said, I'm super new to Ember so please tell me if I'm being stupid. :)