Class: Components::Form

Inherits:
Superform::Rails::Form show all
Includes:
Phlex::Rails::Helpers::Pluralize
Defined in:
lib/generators/superform/install/templates/base.rb

Defined Under Namespace

Classes: Field

Constant Summary

Constants inherited from Superform::Rails::Form

Superform::Rails::Form::Field

Instance Attribute Summary

Attributes inherited from Superform::Rails::Form

#model

Instance Method Summary collapse

Methods inherited from Superform::Rails::Form

#build_field, #form_tag, #initialize, #key, #submit, #view_template

Constructor Details

This class inherits a constructor from Superform::Rails::Form

Instance Method Details

#around_templateObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/generators/superform/install/templates/base.rb', line 22

def around_template(&)
  super do
    # Renders error messages if there are any validation errors on the model
    error_messages
    # Renders the contents of the form from `view_template` or the block passed
    # the #render method.
    yield if block_given?
    # Renders the submit button for the form.
    submit
  end
end

#error_messagesObject

Displays error messages for the form's model if there are any validation errors.



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/superform/install/templates/base.rb', line 38

def error_messages
  if model.errors.any?
    div(style: "color: red;") do
      h2 { "#{pluralize model.errors.count, "error"} prohibited this post from being saved:" }
      ul do
        model.errors.each do |error|
          li { error.full_message }
        end
      end
    end
  end
end

#row(component) ⇒ Object

Wraps a form field and its label in a div for layout purposes.



52
53
54
55
56
57
# File 'lib/generators/superform/install/templates/base.rb', line 52

def row(component)
  div do
    render component.field.label(style: "display: block;")
    render component
  end
end