From 4bccbac0ee6a2b4b3cfb8b14dcd91c5004f3c276 Mon Sep 17 00:00:00 2001 From: Felipe Zavan Date: Thu, 22 Jun 2017 03:50:35 -0300 Subject: [PATCH] Update docs for Reform/Validation - To make the form available inside the validation block configuration we now pass `with: {form: true}` as options to the validation method call, instead of calling `option :form` inside the configure method; - Tell about `:i18n` being the default error message source for dry-validation when the I18n const is defined. --- gems/reform/validation.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gems/reform/validation.md b/gems/reform/validation.md index fdc15cfd..ea9413d0 100644 --- a/gems/reform/validation.md +++ b/gems/reform/validation.md @@ -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 @@ -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 @@ -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: