Hi I'm working with Ember JS and tryingt o validate some and save a user.
I'm using the bellow code.
import Ember from 'ember';
export default Ember.Controller.extend({
isValid: Ember.computed(
'model.email',
'model.firstName',
'model.lastName',
'model.twitter',
{
get() {
return !Ember.isEmpty(this.get('model.email')) &&
!Ember.isEmpty(this.get('model.firstName')) &&
!Ember.isEmpty(this.get('model.lastName')) &&
!Ember.isEmpty(this.get('model.twitter'));
}
}
),
actions: {
save() {
if(this.get('isValid')) {
this.get('model').save().then((friend) => {
this.transitionToRoute('friends.show', friend);
});
} else {
this.set('errorMessage', 'You need to fill in all fields');
}
return false;
},
cancel() {
this.transitionToRoute('friends');
return false;
}
}
});
My problem 'You need to fill in all fields'. Cancel works fine.
Everythign else should be correct but for some reaosn this section is not running.
Aucun commentaire:
Enregistrer un commentaire