Functions for validating input and setting string errors on fields.
All fields are simply keys, meaning this can be a general error storage and
retrieval mechanism for the lifetime of a single request. Errors are not
persisted and are cleaned out at the end of the request.
(errors? & field)
For all fields given return true if any field contains errors. If none of the fields
contain errors, return false. If no fields are supplied return true if any errors exist.
(get-errors & [field])
Get the errors for the given field. This will return a vector of all error strings or nil.
Returns true if v is truthy and not an empty string.
Returns true if all members of the collection has-value? This works on maps as well.
Returns true if v is an email address
(max-length? v len)
Returns true if v is less than or equal to the given len
(min-length? v len)
Returns true if v is greater than or equal to the given len
Returns true if v is not nil
(on-error field func)
If the given field has an error, execute func and return its value
(rule passed? [field error])
If the passed? condition is not met, add the error text to the given field:
(rule (not-nil? username) [:username "Usernames must have a value."])
(set-error field error)
Explicitly set an error for the given field. This can be used to
create complex error cases, such as in a multi-step login process.