You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a signup form, that performs some validation on the server (is the email already taken). When I get the server response, I set a flad emailTaken and run an inline validator:
importEmberfrom'ember';importEmberValidationsfrom'ember-validations';exportdefaultEmber.ObjectController.extend(EmberValidations.Mixin,{validations: {email: {presence: true,inline: EmberValidations.validator(function(){if(this.model.get('emailTaken')){return'email already taken';}})}},actions: {signUp: function(){varself=this;Ember.$.ajax({//...}).then(function(response){self.model.setProperties(response.user);self.transitionToRoute('sessions/confirmation');},function(response){if(response.responseJSON.errors.indexOf('email_taken')!==-1){self.set('emailTaken',true);self.set('error','Damn fuck');}self.validate();// validates fine but doesn't rerender the form});}}});
So the validation runs fine but the form doesn't re-render. Can I do that manually, or bind it to the validation?
The text was updated successfully, but these errors were encountered:
Hi @karellm, I hope you've figured this out by now, but in case you haven't I ran across the same issue, and this is how I solved it
actions: {
saveInvite: function() {
var self = this;
var onSaveSuccess = function(response) {
// ...
};
var onSaveFailure = function(response) {
var errors = response.errors
var errorKeys = Object.keys(errors);
for (var i = 0; i < errorKeys.length; i++) {
var s = 'errors.' + errorKeys[i];
self.model.set(s, [errors[errorKeys[i]]]);
}
};
self.model.save().then(onSaveSuccess, onSaveFailure);
}
}
In a nutshell, I get the errors back from the server, and then get the error keys from Object.keys(errors), then I loop through the errors and add them to the model by hand.
Note that in model.set('errors.email', ['Email is already taken']) I pass an array because otherwise the validation message is nill.
I have a signup form, that performs some validation on the server (is the email already taken). When I get the server response, I set a flad
emailTaken
and run an inline validator:So the validation runs fine but the form doesn't re-render. Can I do that manually, or bind it to the validation?
The text was updated successfully, but these errors were encountered: