Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced field validation #36

Open
rchild-okta opened this issue Jun 25, 2017 · 1 comment
Open

Advanced field validation #36

rchild-okta opened this issue Jun 25, 2017 · 1 comment

Comments

@rchild-okta
Copy link

Are there any plans to support more complex scenarios for field validation? It looks like ion currently has required, type checking, min/max checks, and a catch-all using one regex pattern.

For context, JSON Schema supports a couple properties that make it pretty flexible:

  • format - shortcut for standard validation checks like date-time, email, etc, but is also left open to custom formats that can be used when field level pattern validation is not possible (checking a field against another field, making an api request to validate).

  • allOf, anyOf, oneOf, not - this allows you to combine schemas (useful in general to cut down on boilerplate), but for validation it can also be used to break up a set of checks. For example, let's say we wanted to enforce complexity requirements on a password field:

    "password": {
      "type": "string",
      "title": "Password",
      "required": true,
      "minLength": 2,
      "maxLength": 20,
      "allOf": [
        {
          "description": "At least one lowercase character",
          "pattern": "[a-z]"
        },
        {
          "description": "At least one uppercase character",
          "pattern": "[A-Z]"
        },
        {
          "description": "At least one number",
          "pattern": "[0-9]"
        }
      ]
    }

    This is possible in ion using one pattern constructed of these 3 constraints, but the client wouldn't be able to surface different error messages to the user - you'd only get one shot to say "password invalid" or "password must be one lowercase, one uppercase, and one number". This case is pretty simple, but with more complexity requirements, the pattern could get unwieldy to construct as well.

@lhazlewood
Copy link
Member

@rchild-okta just a note - I haven't forgotten about this, and it's a great point. I'll be able to reply with an example of defining custom contexts probably after Oktane.

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

No branches or pull requests

2 participants