fix validate returning the wrong thing on success, remove error messages on successfu...
authorScott Baker <smbaker@gmail.com>
Wed, 26 Nov 2014 09:04:38 +0000 (01:04 -0800)
committerScott Baker <smbaker@gmail.com>
Wed, 26 Nov 2014 09:04:38 +0000 (01:04 -0800)
planetstack/core/xoslib/static/js/xoslib/xos-backbone.js
planetstack/core/xoslib/static/js/xoslib/xosHelper.js

index a04fd8f..417132d 100644 (file)
@@ -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
             }
     });
 
index dc66e45..2fa9554 100644 (file)
@@ -268,6 +268,8 @@ XOSDetailView = Marionette.ItemView.extend({
                 var that = this;\r
                 var isNew = !this.model.id;\r
 \r
+                this.$el.find(".help-inline").remove();\r
+\r
                 /* although model.validate() is called automatically by\r
                    model.save, we call it ourselves, so we can throw up our\r
                    validation error before creating the infoMsg in the log\r
@@ -369,7 +371,6 @@ XOSDetailView = Marionette.ItemView.extend({
               },\r
 \r
             onFormDataInvalid: function(errors) {\r
-                this.$el.find(".help-inline").remove();\r
                 var self=this;\r
                 var markErrors = function(value, key) {\r
                     console.log("name='" + key + "'");\r