Skip to content

Collection namespaces use Superform::Field instead of ApplicationForm::Field #7

@dhnaranjo

Description

@dhnaranjo
class PageForm < ApplicationForm
  def template
    div do
      field(:id).input
      collection(:responses).each do |response_fields|
        response_fields.field(:option_id).input
      end
    end
  end
end

The call to field(:id) returns an instance of ApplicationForm::Field, while the one inside the collection returns Superform::Field, so input and all my custom fields are unavailable.

My stupid hack is to monkeypatch Superform::Namespace.

module Superform
  class Namespace < Node
    def initialize(key, parent:, object: nil, field_class: ApplicationForm::Field)
      super(key, parent:)
      @object = object
      @field_class = field_class
      @children = {}
      yield self if block_given?
    end
  end
end

You got a better idea of how to handle this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions