schema = Dry::Validation.Form do
required(:single).filled(:bool?)
optional(:participant2).maybe(:str?)
rule(second_participant: [:single, :participant2]) do |single, participant2|
single.false?.then(participant2.filled?)
end
end
how to achieve this behavior today, in version 1.6 ?
- How to write conditional validations like ActiveModel
if:
, dependent on another key in schema - using macros/predicates like
filled
in rules. (participant2.filled?)
I read all docs,
schema = Dry::Validation.Form do
required(:single).filled(:bool?)
optional(:participant2).maybe(:str?)
rule(:participant2, :single) do
key.failure(:must_be_filled) if !values[:single] && values[:participant2].blank?
# How to remove code duplication (replace key.failure(:must_be_filled) to participant2.filled?)
# this is possible?
end
end