From 10fc8757157c97df64825ac0b2b6a6592403e0dc Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 13 Aug 2014 17:00:59 -0700 Subject: [PATCH] Fixed: Validation errors showing multiple times --- src/UI/Mixins/AsValidatedView.js | 10 +++++++++- src/UI/jQuery/jquery.validation.js | 14 +++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/UI/Mixins/AsValidatedView.js b/src/UI/Mixins/AsValidatedView.js index 203efa06b..ea28861eb 100644 --- a/src/UI/Mixins/AsValidatedView.js +++ b/src/UI/Mixins/AsValidatedView.js @@ -8,6 +8,7 @@ define( return function () { + var originalInitialize = this.prototype.initialize; var originalOnRender = this.prototype.onRender; var originalBeforeClose = this.prototype.onBeforeClose; @@ -47,7 +48,7 @@ define( } }; - this.prototype.onRender = function () { + this.prototype.initialize = function (options) { if (this.model) { this.listenTo(this.model, 'validation:sync', function () { @@ -65,6 +66,13 @@ define( this.listenTo(this, 'validation:failed', validationFailed); } + if (originalInitialize) { + originalInitialize.call(this, options); + } + }; + + this.prototype.onRender = function () { + Validation.bind(this); this.bindToModelValidation = bindToModel.bind(this); diff --git a/src/UI/jQuery/jquery.validation.js b/src/UI/jQuery/jquery.validation.js index ba1f80d90..661e8310b 100644 --- a/src/UI/jQuery/jquery.validation.js +++ b/src/UI/jQuery/jquery.validation.js @@ -36,16 +36,16 @@ define( } } - var controlGroup = input.parents('.form-group'); + var formGroup = input.parents('.form-group'); - if(controlGroup.length === 0) { - controlGroup = input.parent(); + if(formGroup.length === 0) { + formGroup = input.parent(); } else{ - var inputGroup = controlGroup.find('.input-group'); + var inputGroup = formGroup.find('.input-group'); if (inputGroup.length === 0) { - controlGroup.append('' + errorMessage + ''); + formGroup.append('' + errorMessage + ''); } 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(); };