Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Validator function setting multiple types of errors #6

Open
Rush opened this issue Jul 13, 2015 · 4 comments
Open

Validator function setting multiple types of errors #6

Rush opened this issue Jul 13, 2015 · 4 comments

Comments

@Rush
Copy link

Rush commented Jul 13, 2015

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?

@timc13
Copy link

timc13 commented Jan 5, 2016

+1

@PowerKiKi
Copy link
Contributor

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

@geemang2000
Copy link

+1

1 similar comment
@kenandjackie
Copy link

+1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants