reforms.validation

Validation functionality.

*validation-errors*

dynamic

all

(all & validators)

Groups validators using ‘and’ boolean logic.

button

(button & args)

Wrapper for reforms.core/button adding support for validation.

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.

checkbox

(checkbox & args)

Wrapper for reforms.core/checkbox adding support for validation.

color

(color & args)

Wrapper for reforms.core/color adding support for validation.

date

(date & args)

Wrapper for reforms.core/date adding support for validation.

datetime

(datetime & args)

Wrapper for reforms.core/datetime adding support for validation.

datetime-local

(datetime-local & args)

Wrapper for reforms.core/datetime-local adding support for validation.

email

(email & args)

Wrapper for reforms.core/email 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])

find-validation-error

(find-validation-error kork errors)

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.

html5-input

(html5-input & args)

Wrapper for reforms.core/html5-input adding support for validation.

invalid?

Complement of valid?

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"]

month

(month & args)

Wrapper for reforms.core/month adding support for validation.

no-error

(no-error)

Generates a ‘no error’ placeholder.

number

(number & args)

Wrapper for reforms.core/number adding support for validation.

password

(password & args)

Wrapper for reforms.core/password adding support for validation.

present

(present korks error-message)

Presence validator.

Example:

(present [:user :login] "Enter the login"]

present?

(present? x)

render-errors

(render-errors errors)

Renders errors as unordered list.

Arguments:

  • errors - results of validation

select

(select & args)

Wrapper for reforms.core/select adding support for validation.

sequable?

(sequable? x)

tel

(tel & args)

Wrapper for reforms.core/tel adding support for validation.

text

(text & args)

Wrapper for reforms.core/text adding support for validation.

textarea

(textarea & args)

Wrapper for reforms.core/textarea adding support for validation.

time

(time & args)

Wrapper for reforms.core/time adding support for validation.

url

(url & args)

Wrapper for reforms.core/url adding support for 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-field

(validating-field field-fn & args)

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.

week

(week & args)

Wrapper for reforms.core/week adding support for validation.