reforms.validation
Validation functionality.
button-default
(button-default & args)
Wrapper for reforms.core/button-default adding support for validation.
button-primary
(button-primary & args)
Wrapper for reforms.core/button-primary adding support for validation.
datetime-local
(datetime-local & args)
Wrapper for reforms.core/datetime-local adding support for validation.
equal
(equal korks1 korks2 error-message)
Equality validator.
Example:
(equal [:user :password1] [:user :password2] "Passwords do not match"]
error-alert
(error-alert & korks)
Renders errors for specified key seqs.
Example:
(error-alert [:user :name] [:my-custom-error])
force-error
(force-error korks error-message)
Generates an error. Useful for errors not coming from data but from external sources such as Ajax or RPC.
Example:
(force-error [:server-error] "Problem connecting to the REST API server")
form
macro
(form cursor & args)
Wrapper for reforms.core/form. This is a macro.
It accepts the same args as reforms.core/form except there’s an extra one in front: cursor
to store validation results in.
is-true
(is-true korks f error-message)
Predicate-based validator.
Example:
(is-true [:user :email] #(nil? (find-by-email %)) “Email already exists”]
matches
(matches korks re error-message)
Regex validator.
Example:
(matches [:user :email] #"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$" "Invalid email address"]
present
(present korks error-message)
Presence validator.
Example:
(present [:user :login] "Enter the login"]
render-errors
(render-errors errors)
Renders errors as unordered list.
Arguments:
- errors - results of validation
valid?
(valid? errors)
(valid? kork errors)
Returns true if there are no errors.
Arguments:
- errors - result of validation
- kork - (optional) match against this key seq
validate
(validate data & validators)
Validates data and returns a list of errors.
Arguments:
- data - data to validate
- validators - seq of validators to use
validate!
(validate! cursor ui-state-cursor & validators)
Validates data and saves the result. A stateful method.
Arguments:
- cursor - the data to validate
- ui-state-cursor - this is where validation result will be stored
- validators - a seq of validators
validating-fields
macro
(validating-fields validation-errors & body)
Low-level macro to wrap validating fields. Normally you’ll use the reforms.validation/form macro.
Example:
(let [errors (validation-errors ui-state)]
(form
(validating-fields
errors
(text ...)
(text ...))))
validating-fields-fn
(validating-fields-fn validation-errors & fields)
Used by [reforms.validation/validating-fields] macro.
validation-error
(validation-error korks error-message)
Returns a validation error for a key sequence.
Arguments:
- korks - key sequence the error refers to
- error-message - string containing the error message
validation-errors
(validation-errors ui-state-cursor)
Returns validation errors saved by validate! into ui-state-cursor.