Skip to content
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

Form processor with type specs doesn't coerce int arrays inside hashes #369

Closed
Morozzzko opened this issue Oct 11, 2017 · 4 comments
Closed

Comments

@Morozzzko
Copy link
Member

Morozzzko commented Oct 11, 2017

If you use Dry::Validation:Form with type_specs = true and arrays inside hashes (see example below), it won't coerce the values inside the array and fail instead.

        Dry::Validation.Form do
          configure do
            config.type_specs = true
          end

          required(:foo).schema do
            required(:bar, :array).each(:int?)
          end
        end

There are two workarounds I have found:

  1. Don't use the type_specs (duh) (probably not a good solution)
  2. Define a type similar to IntArray = Dry::Types['form.array'].of(Dry::Types['coercible.int']) and use it in the validation block (required(:bar, IntArray).each(:int?))

This seems like a bug, so I'm opening this issue

UPD: wrote some tests to demonstrate both the problem and the 2nd solution workaround

@flash-gordon
Copy link
Member

It's not obvious how it should work in dry-schema

required(:bar).value(:array).each(Types::Params::Integer, :int?)

throws an error

@flash-gordon
Copy link
Member

probably related to #424 and #291

@solnic
Copy link
Member

solnic commented Feb 6, 2019

@flash-gordon re your example, please report an issue in dry-schema, and here's what should work:

required(:bar).value(array[:integer]).each(:int?)

@flash-gordon
Copy link
Member

ref dry-rb/dry-schema#21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants