From d8b0d5cb77e0b40c4718ff4eea80bc9f96eaea94 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Wed, 26 Nov 2014 01:04:38 -0800 Subject: [PATCH] fix validate returning the wrong thing on success, remove error messages on successful validate --- planetstack/core/xoslib/static/js/xoslib/xos-backbone.js | 7 ++++++- planetstack/core/xoslib/static/js/xoslib/xosHelper.js | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js index a04fd8f..417132d 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js +++ b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js @@ -72,17 +72,22 @@ if (! window.XOSLIB_LOADED ) { validate: function(attrs, options) { errors = {}; + foundErrors = false; _.each(this.validators, function(validatorList, fieldName) { _.each(validatorList, function(validator) { if (fieldName in attrs) { validatorResult = validateField(validator, attrs[fieldName]) if (validatorResult != true) { errors[fieldName] = validatorResult; + foundErrors = true; } } }); }); - return errors; + if (foundErrors) { + return errors; + } + // backbone.js semantics -- on successful validate, return nothing } }); diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js index dc66e45..2fa9554 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js +++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js @@ -268,6 +268,8 @@ XOSDetailView = Marionette.ItemView.extend({ var that = this; var isNew = !this.model.id; + this.$el.find(".help-inline").remove(); + /* although model.validate() is called automatically by model.save, we call it ourselves, so we can throw up our validation error before creating the infoMsg in the log @@ -369,7 +371,6 @@ XOSDetailView = Marionette.ItemView.extend({ }, onFormDataInvalid: function(errors) { - this.$el.find(".help-inline").remove(); var self=this; var markErrors = function(value, key) { console.log("name='" + key + "'"); -- 2.43.0