Advanced field validation
Opened this issue · 1 comments
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.
@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.