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

Nested MultiParameter Attributes not converted #52

Open
devpost-mzheng opened this issue May 19, 2017 · 1 comment
Open

Nested MultiParameter Attributes not converted #52

devpost-mzheng opened this issue May 19, 2017 · 1 comment

Comments

@devpost-mzheng
Copy link

Dates that are nested don't seem to be converted from multi params to a date. For example

  include Reform::Form::MultiParameterAttributes
  
  property :something_nested do
    property :some_date, multi_params: true

It looks like it skips over the logic to convert the params to date because the nested params come in as type ActionController::Parameters and not as a Hash

I was able to fix this in a forked branch by doing

      params.each do |attribute, value|
        if value.respond_to?(:to_hash) #instead of value.is_a?(Hash)
          params[attribute] = call(value) # TODO: #validate should only handle local form params.
        elsif matches = attribute.match(/^(\w+)\(.i\)$/)
          date_attribute = matches[1]
          date_attributes[date_attribute] = params_to_date(
            params.delete("#{date_attribute}(1i)"),
            params.delete("#{date_attribute}(2i)"),
            params.delete("#{date_attribute}(3i)"),
            params.delete("#{date_attribute}(4i)"),
            params.delete("#{date_attribute}(5i)")
          )
        end
      end

Any thoughts on a better way to do this or perhaps I am missing some options?

@apotonick
Copy link
Member

We might have to add this check, then. Thanks!

The real solution here is to push the Formular gem since we can ditch this entire hack, then.

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

2 participants