Hi
Let’s say I have this form:
class Form < Dry::Validation
params do
optional(:phones).maybe do
each do
hash do
required(:id).filled(:integer)
required(:names).filled(:array, min_size?: 1) do
each(:integer)
end
end
end
end
end
rule(:phones).each do |index:|
if values[:phones][index].dig(:id)
key([:phones, index, :id]).failure("doesn't exist") unless check_id(values[:phones][index][:id])
end
end
end
given data:
data = {phones: nil}
I get an error when I try to validate my form:
form = Form.new
form.call(data) => Undefined method `each_with_index'
Do you know how Can I overcome this problem? I want phones to accept nil value. I’ve been thinking about overwriting #rule method but I don’t know where to start.
Thanks in advance!