Class: Superform::Rails::Form::Field

Inherits:
Field
  • Object
show all
Defined in:
lib/superform/rails.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 < 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

Constructor Details

This class inherits a constructor from Superform::Field

Instance Method Details

#button(**attributes) ⇒ Object



48
49
50
# File 'lib/superform/rails.rb', line 48

def button(**attributes)
  Components::ButtonComponent.new(self, attributes: attributes)
end

#checkbox(**attributes) ⇒ Object



56
57
58
# File 'lib/superform/rails.rb', line 56

def checkbox(**attributes)
  Components::CheckboxComponent.new(self, attributes: attributes)
end

#input(**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



64
65
66
# File 'lib/superform/rails.rb', line 64

def textarea(**attributes)
  Components::TextareaComponent.new(self, attributes: attributes)
end

#titleObject



72
73
74
# File 'lib/superform/rails.rb', line 72

def title
  key.to_s.titleize
end