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

Validator function setting multiple types of errors #6

@Rush

Description

@Rush

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions