ui-validate icon indicating copy to clipboard operation
ui-validate copied to clipboard

Validator function setting multiple types of errors

Open Rush opened this issue 9 years ago • 4 comments

I need to have one function that validates a field that can have multiple error types. Splitting this validator to multiple separate functions is not practical due to the amount of code required to parse this input. I have created a my own variation of the uiValidate directive with instead of:

        ctrl.$validators[key] = validateFn;

having this:

        ctrl.$validators[key] = function(value) {
          if(ctrl._validatedKey) {
            ctrl.$setValidity(ctrl._validatedKey, true);
            delete ctrl._validatedKey;
          }

          var retVal = validateFn(value);
          if(angular.isString(retVal)) {
            ctrl.$setValidity(retVal, false);
            ctrl._validatedKey = retVal;
            return false;
          }
          return retVal;
        };

So basically in a validator function instead of returning return false; I can do return "errorFoo" or return "errorBar" depending on the error.

Is such a feature welcome in this library, should I bother with a pull request or keep my changes local?

Rush avatar Jul 13 '15 17:07 Rush

+1

timc13 avatar Jan 05 '16 21:01 timc13

@Rush, it seems your suggestion is interesting for other people too. If you are still willing to submit a PR, I'd merge it.

PowerKiKi avatar Jan 08 '16 01:01 PowerKiKi

+1

geemang2000 avatar Aug 11 '16 13:08 geemang2000

+1

kenandjackie avatar May 04 '17 17:05 kenandjackie