Fixed: Error messages not being shown in the UI or being shown in the wrong place

This commit is contained in:
Mark McDowall 2014-06-04 08:38:26 -07:00
parent 9916479f02
commit 545bc756f2
13 changed files with 66 additions and 34 deletions

View file

@ -12,19 +12,12 @@ define(
var originalBeforeClose = this.prototype.onBeforeClose;
var errorHandler = function (response) {
if (response.status === 400) {
var view = this;
var validationErrors = JSON.parse(response.responseText);
_.each(validationErrors, function (error) {
view.$el.processServerError(error);
});
}
this.model.trigger('validation:failed', response);
};
var validatedSync = function (method, model,options) {
this.$el.removeAllErrors();
var validatedSync = function (method, model, options) {
model.trigger('validation:sync');
// this.$el.removeAllErrors();
arguments[2].isValidatedCall = true;
return model._originalSync.apply(this, arguments).fail(errorHandler.bind(this));
};
@ -39,6 +32,21 @@ define(
this.prototype.onRender = function () {
this.listenTo(this.model, 'validation:sync', function () {
this.$el.removeAllErrors();
});
this.listenTo(this.model, 'validation:failed', function (response) {
if (response.status === 400) {
var view = this;
var validationErrors = JSON.parse(response.responseText);
_.each(validationErrors, function (error) {
view.$el.processServerError(error);
});
}
});
Validation.bind(this);
this.bindToModelValidation = bindToModel.bind(this);
@ -55,6 +63,10 @@ define(
if (this.model) {
Validation.unbind(this);
//If we don't do this the next time the model is used the sync is bound to an old view
this.model.sync = this.model._originalSync;
this.model._originalSync = undefined;
}
if (originalBeforeClose) {