Skip to content

Commit eab653d

Browse files
committed
Add comments and more to the base Superform template
1 parent aecebca commit eab653d

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

  • lib/generators/superform/install/templates
Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,40 @@
11
module Components
22
class Form < Superform::Rails::Form
3-
include Phlex::Rails::Helpers::Pluralize
4-
5-
def row(component)
6-
div do
7-
render component.field.label(style: "display: block;")
8-
render component
9-
end
3+
# Extend the Field class to add your own custom helpers.
4+
class Field < self::Field
5+
# # Overide base form helpers for small modifications, like injecting
6+
# # default classes or styles.
7+
# def input(class: nil, **)
8+
# super(class: ["border p-2", grab(class:)], **)
9+
# end
10+
#
11+
# # Create custom field helpers that may be accessed via `fied(:email).my_input`
12+
# def required_email(**)
13+
# input(type: "email", required: true, **)
14+
# end
15+
#
16+
# # Return your own component if you're doing more complicated things.
17+
# def autocomplete(**attributes)
18+
# Components::Autocomplete.new(field, attributes:)
19+
# end
1020
end
1121

1222
def around_template(&)
1323
super do
24+
# Renders error messages if there are any validation errors on the model
1425
error_messages
26+
# Renders the contents of the form from `view_template` or the block passed
27+
# the #render method.
1528
yield if block_given?
29+
# Renders the submit button for the form.
1630
submit
1731
end
1832
end
1933

34+
# This is needed for the `error_messages`
35+
include Phlex::Rails::Helpers::Pluralize
36+
37+
# Displays error messages for the form's model if there are any validation errors.
2038
def error_messages
2139
if model.errors.any?
2240
div(style: "color: red;") do
@@ -29,5 +47,13 @@ def error_messages
2947
end
3048
end
3149
end
50+
51+
# Wraps a form field and its label in a div for layout purposes.
52+
def row(component)
53+
div do
54+
render component.field.label(style: "display: block;")
55+
render component
56+
end
57+
end
3258
end
3359
end

0 commit comments

Comments
 (0)