Skip to content

NamespaceCollection enumerate building enumerable repeatedly #8

@dhnaranjo

Description

@dhnaranjo

I don't super understand exactly what happened here. I was doin a lil something like this:

class PageForm < ApplicationForm
  def template
    div do
      collection(:responses).each do |response_fields|
        response = response_fields.object
        item = response.item
        options = item.options.pluck(:id, :label)
        render response_fields.field(:option_id).radio(options)
      end
    end
  end
end

And whenever I'd assign the params it seemed like the NamespaceCollection was building the namespaces array twice, overwriting the first, so that my namespaces didn't have any children, so no update was made.

This makes it work. I'm not really sure why.

module Superform
  class NamespaceCollection < Node
    def enumerate(enumerable)
      enumerable.map.with_index do |object, key|
        build_namespace(key, object:)
      end
    end
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions