rubymonolith / superform

Build highly customizable forms in Rails
MIT License
263 stars 14 forks source link

ArgumentError wrong number of arguments (given 1, expected 2..4) in render #41

Open BarnabeD opened 3 weeks ago

BarnabeD commented 3 weeks ago

Hi everyone, I'm trying to add SuperForm for the first time in my phlex app. I try to add a really light form with only one field email for a contact form. No collection, no namespace etc..

I encounter a strange error within the default generated ApplicationForm on this line render component.field.label

class ApplicationForm < Superform::Rails::Form
  include Phlex::Rails::Helpers::Pluralize

  def row(component)
    div do
      render component.field.label
      render component
    end
  end
# [...]
end

If I comment : render component.field.label my input is render with no errors. So, render componentis working well.

I try with differents form versions :

V1 default Readme exemple -> ArgumentError wrong number of arguments (given 1, expected 2..4)

class Public::Contacts::Form < ApplicationForm
  def view_template(&)
    row field(:email).input
  end
end

V2 bypass row -> ArgumentError [...] is not an ActiveModel-compatible object. It must implement #to_partial_path. Like: #39

class Public::Contacts::Form < ApplicationForm
  def view_template(&)
    render field(:email) do |f|
      div do
        f.label { "Email :" }
        f.input
      end
    end
  end
end

In V1 and V2, inputs are rendered without error if the label line is commented. I don't understand why render component.field.label raise ArgumentError and not render component. Maybe it's related to render changes in Phlex ?

Versions :

Note :

I started with SuperForm a few hours ago, so I apologize if I'm missing something obvious.