-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot validate form when using Composition and dry-validation #451
Comments
We have the same here:
|
We're having this too. Essentially, it's very similar to If you do validation :default do
required(:investor).schema do
required(:location_country).filled(:str?)
end
required(:user).schema do
required(:first_name).filled(:str?)
required(:last_name).filled(:str?)
end
end Then your validation will work, but the errors hash produced will not be usable with rails style form builders. So we have a problem of what hash is being passed to dry-v |
More info, issue is here: In file def to_nested_hash(*)
hash = {}
@model.each do |name, model| # TODO: provide list of composee attributes in Composition.
part_properties = schema.find_all { |dfn| dfn[:on] == name }.collect{ |dfn| dfn[:name].to_sym }
hash[name] = self.class.nested_hash_representer.new(self).to_hash(include: part_properties)
end
hash
end The method is geared to iterate over the models. But we need to use a non nested hash in reform::form... The fix depends on whether Composition in twin is doing the wrong thing with nested_hash (which looks right to me) or if reform's supposed to use a flat hash... |
In 2.1.0, def valid?
Groups::Result.new(self.class.validation_groups).(@fields, errors, self)
end But in 2.2.4 def valid?
Groups::Result.new(self.class.validation_groups).(to_nested_hash, errors, self)
end I think it should be @fields, not to_nested_hash |
Complete Description of Issue
When using dry-validation for validation and using Composition, I cannot get the form to validate.
Steps to reproduce
Expected behavior
It should validate
Actual behavior
It does not validate
System configuration
reform 2.2.4
dry-validation 0.11.1
rails 5.2.0.beta2
The text was updated successfully, but these errors were encountered: