Class: Superform::Form

Inherits:
Phlex::HTML
  • Object
show all
Defined in:
lib/superform/form.rb

Overview

A basic form component that inherits from Phlex::HTML and wraps content in a form tag. This provides a simple foundation for building forms without Rails dependencies.

Example usage:

class MyForm < Superform::Form
  def view_template
    div { "Form content goes here" }
  end
end

form = MyForm.new(action: "/users", method: :post)
form.call # renders <form action="/users" method="post">...</form>

Instance Method Summary collapse

Constructor Details

#initialize(action: nil, method: :post, **attributes) ⇒ Form

Returns a new instance of Form.



19
20
21
22
23
24
# File 'lib/superform/form.rb', line 19

def initialize(action: nil, method: :post, **attributes)
  @action = action
  @method = method
  @attributes = attributes
  super()
end

Instance Method Details

#around_template(&block) ⇒ Object



26
27
28
# File 'lib/superform/form.rb', line 26

def around_template(&block)
  form(action: @action, method: @method, **@attributes, &block)
end

#build_field(key, parent:, object: nil, &block) ⇒ Object



30
31
32
# File 'lib/superform/form.rb', line 30

def build_field(key, parent:, object: nil, &block)
  Field.new(key, parent: parent, object: object, &block)
end