Class: Protoform::Rails::Form::Field
- Inherits:
-
Field
- Object
- Node
- Field
- Protoform::Rails::Form::Field
show all
- Defined in:
- lib/protoform/rails/form/field.rb
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 < Protoform::Rails::Form
class MyLabel < Protoform::Rails::Components::LabelComponent
def view_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, #object
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
27
28
29
|
# File 'lib/protoform/rails/form/field.rb', line 27
def button(...)
Components::Button.new(self, ...)
end
|
#checkbox ⇒ Object
35
36
37
|
# File 'lib/protoform/rails/form/field.rb', line 35
def checkbox(...)
Components::Checkbox.new(self, ...)
end
|
#date ⇒ Object
39
40
41
|
# File 'lib/protoform/rails/form/field.rb', line 39
def date(...)
Components::Date.new(self, ...)
end
|
#datetime ⇒ Object
47
48
49
|
# File 'lib/protoform/rails/form/field.rb', line 47
def datetime(...)
Components::Datetime.new(self, ...)
end
|
31
32
33
|
# File 'lib/protoform/rails/form/field.rb', line 31
def input(...)
Components::Input.new(self, ...)
end
|
#label ⇒ Object
55
56
57
|
# File 'lib/protoform/rails/form/field.rb', line 55
def label(...)
Components::Label.new(self, ...)
end
|
51
52
53
|
# File 'lib/protoform/rails/form/field.rb', line 51
def radio_button(value, **)
Components::RadioButton.new(self, value:, **)
end
|
#select(*collection, **attributes, &block) ⇒ Object
63
64
65
66
67
68
69
70
|
# File 'lib/protoform/rails/form/field.rb', line 63
def select(*collection, **attributes, &block)
Components::Select.new(
self,
collection:,
**attributes,
&block
)
end
|
#textarea ⇒ Object
59
60
61
|
# File 'lib/protoform/rails/form/field.rb', line 59
def textarea(...)
Components::Textarea.new(self, ...)
end
|
#time ⇒ Object
43
44
45
|
# File 'lib/protoform/rails/form/field.rb', line 43
def time(...)
Components::Time.new(self, ...)
end
|
#title ⇒ Object
72
73
74
|
# File 'lib/protoform/rails/form/field.rb', line 72
def title
key.to_s.titleize
end
|