Class: Superform::Rails::Form::Field
Overview
The Field class is designed to be extended to create custom forms. To override, in your subclass you may have something like this:
“‘ruby class MyForm < Superform::Rails::Form
class MyLabel < Superform::Rails::Components::LabelComponent
def template(&content)
label(form: @field.dom.name, class: "text-bold", &content)
end
end
class Field < Field
def label(**attributes)
MyLabel.new(self, **attributes)
end
end
end “‘
Now all calls to ‘label` will have the `text-bold` class applied to it.
Instance Attribute Summary
Attributes inherited from Field
#dom
Attributes inherited from Node
#key, #parent
Instance Method Summary
collapse
Methods inherited from Field
#assign, #collection, #initialize, #value
Methods inherited from Node
#initialize
Instance Method Details
48
49
50
|
# File 'lib/superform/rails.rb', line 48
def button(**attributes)
Components::ButtonComponent.new(self, attributes: attributes)
end
|
#checkbox(**attributes) ⇒ Object
52
53
54
|
# File 'lib/superform/rails.rb', line 52
def input(**attributes)
Components::InputComponent.new(self, attributes: attributes)
end
|
#label(**attributes) ⇒ Object
60
61
62
|
# File 'lib/superform/rails.rb', line 60
def label(**attributes)
Components::LabelComponent.new(self, attributes: attributes)
end
|
#select(*collection, **attributes) ⇒ Object
68
69
70
|
# File 'lib/superform/rails.rb', line 68
def select(*collection, **attributes, &)
Components::SelectField.new(self, attributes: attributes, collection: collection, &)
end
|
#textarea(**attributes) ⇒ Object
#title ⇒ Object
72
73
74
|
# File 'lib/superform/rails.rb', line 72
def title
key.to_s.titleize
end
|