Fixed: Validation errors showing multiple times

This commit is contained in:
Mark McDowall 2014-08-13 17:00:59 -07:00
parent 9e9cb98b3a
commit 10fc875715
2 changed files with 16 additions and 8 deletions

View File

@ -8,6 +8,7 @@ define(
return function () { return function () {
var originalInitialize = this.prototype.initialize;
var originalOnRender = this.prototype.onRender; var originalOnRender = this.prototype.onRender;
var originalBeforeClose = this.prototype.onBeforeClose; var originalBeforeClose = this.prototype.onBeforeClose;
@ -47,7 +48,7 @@ define(
} }
}; };
this.prototype.onRender = function () { this.prototype.initialize = function (options) {
if (this.model) { if (this.model) {
this.listenTo(this.model, 'validation:sync', function () { this.listenTo(this.model, 'validation:sync', function () {
@ -65,6 +66,13 @@ define(
this.listenTo(this, 'validation:failed', validationFailed); this.listenTo(this, 'validation:failed', validationFailed);
} }
if (originalInitialize) {
originalInitialize.call(this, options);
}
};
this.prototype.onRender = function () {
Validation.bind(this); Validation.bind(this);
this.bindToModelValidation = bindToModel.bind(this); this.bindToModelValidation = bindToModel.bind(this);

View File

@ -36,16 +36,16 @@ define(
} }
} }
var controlGroup = input.parents('.form-group'); var formGroup = input.parents('.form-group');
if(controlGroup.length === 0) { if(formGroup.length === 0) {
controlGroup = input.parent(); formGroup = input.parent();
} }
else{ else{
var inputGroup = controlGroup.find('.input-group'); var inputGroup = formGroup.find('.input-group');
if (inputGroup.length === 0) { if (inputGroup.length === 0) {
controlGroup.append('<span class="help-inline validation-error">' + errorMessage + '</span>'); formGroup.append('<span class="help-inline validation-error">' + errorMessage + '</span>');
} }
else { else {
@ -53,9 +53,9 @@ define(
} }
} }
controlGroup.addClass('has-error'); formGroup.addClass('has-error');
return controlGroup.find('.help-inline').text(); return formGroup.find('.help-inline').text();
}; };