FacultyCreative / ngActiveResource

Connects business objects and REST web services for Angular.js
255 stars 34 forks source link

Validation rules gets add multiple times #58

Open binnuka opened 10 years ago

binnuka commented 10 years ago

I found that "addValidations" get call multiple times within the code and for each time a validation function get added which make it to run same function multiple times.

binnuka commented 10 years ago

one fix i did was

        function pushValidation(validationKey, value, field, validationObject,key) {
                 // console.log('pushValidation ');
                  var validation = function (val, field, instance) {
                      if (value.validates)
                          value = value.validates;
                      if (validationKey(value)(val, field, instance)) {
                          return true;
                      } else {
                          return false;
                      }
                      ;
                  };
                  if (validationObject.message) {
                      validation.message = validationObject.message;
                  } else if (value.message) {
                      validation.message = value.message;
                  } else {
                      validation.message = validationKey.message(value);
                  }
                  //validations.push(validation);
                  validations[key]=validation;
              }
  where i pass the property key and 

for (var prop in fields[field]) { debugger var validator = fields[field][prop]; if (!isValid(validator, instance, field)) { if (!this.$errors[field]) this.$errors[field] = []; this.$errors[field].nodupush(validator.message); } else { if (!this.$errors[field]) return; .remove(this.$errors[field], function (error) { return error == validator.message; }); if (this.$errors[field].length === 0) { delete this.$errors[field]; } } ; } //.each(fields[field], function (validator) { // debugger // if (!isValid(validator, instance, field)) { // if (!this.$errors[field]) // this.$errors[field] = []; // this.$errors[field].nodupush(validator.message); // } else { // if (!this.$errors[field]) // return; // _.remove(this.$errors[field], function (error) { // return error == validator.message; // }); // if (this.$errors[field].length === 0) { // delete this.$errors[field]; // } // } // ; //}, this); within "this.validate" method

But this does not fix the root cause of callin "addValidations" multiple times, but fix same validation rue running multiple times