Class: Protoform::Rails::Form::Field

Inherits:
Field
  • Object
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

Constructor Details

This class inherits a constructor from Protoform::Field

Instance Method Details

#buttonObject



27
28
29
# File 'lib/protoform/rails/form/field.rb', line 27

def button(...)
  Components::Button.new(self, ...)
end

#checkboxObject



35
36
37
# File 'lib/protoform/rails/form/field.rb', line 35

def checkbox(...)
  Components::Checkbox.new(self, ...)
end

#dateObject



39
40
41
# File 'lib/protoform/rails/form/field.rb', line 39

def date(...)
  Components::Date.new(self, ...)
end

#datetimeObject



47
48
49
# File 'lib/protoform/rails/form/field.rb', line 47

def datetime(...)
  Components::Datetime.new(self, ...)
end

#inputObject



31
32
33
# File 'lib/protoform/rails/form/field.rb', line 31

def input(...)
  Components::Input.new(self, ...)
end

#labelObject



55
56
57
# File 'lib/protoform/rails/form/field.rb', line 55

def label(...)
  Components::Label.new(self, ...)
end

#radio_button(value) ⇒ Object



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

#textareaObject



59
60
61
# File 'lib/protoform/rails/form/field.rb', line 59

def textarea(...)
  Components::Textarea.new(self, ...)
end

#timeObject



43
44
45
# File 'lib/protoform/rails/form/field.rb', line 43

def time(...)
  Components::Time.new(self, ...)
end

#titleObject



72
73
74
# File 'lib/protoform/rails/form/field.rb', line 72

def title
  key.to_s.titleize
end