Closed macklinu closed 7 months ago
This is what I've been able to get working. The only thing I'm not sure about is where errors?
and errors
come from.
class ApplicationForm < Superform::Rails::Form
class MyInputComponent < Superform::Rails::Components::InputComponent
def template(&)
div class: "form-field" do
input(**attributes)
# if field.errors?
# p(class: "form-field-error") { field.errors.to_sentence }
# end
end
end
end
class Field < Superform::Rails::Form::Field
def input(**attributes)
MyInputComponent.new(self, attributes:)
end
end
def labeled(component)
div class: "form-row" do
render component.field.label
render component
end
end
def submit(text)
button(type: :submit) { text }
end
end
If I uncomment the line with field.errors?
, I get an undefined method errors?
error.
Hello, I am trying to get started with Superform and Phlex, but the example in the Customization section is not working with superform v0.4.5. I'd love to figure out what is needed here, because being able to override different form component as mentioned in the superform README styles for usage with Tailwind makes much more sense to me conceptually than messing around with Rails FormBuilder.
Steps to reproduce:
rails new superform_example
cd superform_example
rails g scaffold User name email
rails db migrate
bundle add superform --version 0.4.5
rails g superform:install
Update
app/views/forms/application_form.rb
Create
app/views/users/form.rb
app/views/users/new.html.erb
to render the form:<%= render Users::Form.new @user %>
ActionView::Template::Error (wrong number of arguments (given 2, expected 0)): 1:
New user
2: 3: <%= render Users::Form.new @user %> 4: 5:6:
app/views/forms/application_form.rb:15:in
input' app/views/users/form.rb:3:in
template' app/views/users/new.html.erb:3