Skip to content
This repository was archived by the owner on Aug 16, 2019. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions gems/reform/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@ The purest form of defining validations with this backend is by using a [validat
end
end

Custom predicates have to be defined in the validation group. If you need access to your form you must add `option :form` to your configure block.
Custom predicates have to be defined in the validation group. If you need access to your form you must pass `with: {form: true}` to your validation block.

validation :default do
validation :default, with: {form: true} do
configure do
option :form

def unique?(value)
Album.where.not(id: form.model.id).find_by(title: value).nil?
end
Expand All @@ -125,10 +123,8 @@ Custom predicates have to be defined in the validation group. If you need access

In addition to dry-validation's API, you have access to the form that contains the group via `form`.

validation :default do
validation :default, with: {form: true} do
configure do
option :form

def same_password?(value)
value == form.password
end
Expand All @@ -150,6 +146,8 @@ You need to provide custom error messages via dry-validation mechanics.
# ..
end

This is automatically configured to use the I18n gem if it's available, which is true in a Rails environment.

A simple error messages file might look as follows.

en:
Expand Down