foundation_form_builder 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/foundation_form_builder/rails.rb +18 -0
- data/lib/foundation_form_builder/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51e1b678cf9389ebdd4be33ea71ddef5a9060b66
|
4
|
+
data.tar.gz: f6707a233e7a6c7e74f12b0f270e56078c03d5d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 565073d1aef0d0142078b520b70327cb2dcede9f529f90f1c17c4b3b5abe24592bcc5b33c82fa4443873a1156ec73c48a07fbc0768e02caae2d5abd1431c9485
|
7
|
+
data.tar.gz: 22bb845a176c546359a60adf955bc46981306263bf5c852fd9d0fae44135414a0710cc5af5624f026682aa2d3d709a13446f353a389beeedb84bd0840ae052b9
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,16 @@ require 'active_support/time_with_zone'
|
|
4
4
|
|
5
5
|
module FoundationFormBuilder
|
6
6
|
class Rails < ActionView::Helpers::FormBuilder
|
7
|
+
|
8
|
+
# Renders a form field with label wrapped in an appropriate +<div>+, with another +<div>+ for errors if necessary.
|
9
|
+
#
|
10
|
+
# @param field_name [String, Symbol] Name of the field to render
|
11
|
+
# @option options [Hash] :field Options to pass through to the underlying Rails form helper. For +type: :time_zone+, +:priority_zones+ is also understood.
|
12
|
+
# @option options [String, Symbol] :label (human-readable version of +field_name+) Text for the +<label>+ element
|
13
|
+
# @option options [Symbol] :type (type inferred by #infer_type) Type of field to render.
|
14
|
+
# Known values are +:date+, +:email+, +:password+, +:select+, +:textarea+, and +:time_zone+. Anything else is rendered as a text field.
|
15
|
+
# @option options [Array] :values Name-value pairs for +<option>+ elements. Only meaningful with +type: :select+.
|
16
|
+
# @return [SafeBuffer] The rendered HTML
|
7
17
|
def input_div(field_name, label: nil, type: nil, values: nil, field: {})
|
8
18
|
raise ArgumentError, ':values is only meaningful with type: :select' if values && type != :select
|
9
19
|
@template.content_tag :div, class: field_name do
|
@@ -17,6 +27,10 @@ module FoundationFormBuilder
|
|
17
27
|
|
18
28
|
private
|
19
29
|
|
30
|
+
# Renders a +<div>+ with errors if there are any for the specified field, or returns +nil+ if not.
|
31
|
+
#
|
32
|
+
# @param field_name [String, Symbol] Name of the field to check for errors
|
33
|
+
# @return [SafeBuffer, nil] The rendered HTML or nil
|
20
34
|
def error_div(field_name)
|
21
35
|
error_messages = errors[field_name]
|
22
36
|
if error_messages.present?
|
@@ -55,6 +69,10 @@ module FoundationFormBuilder
|
|
55
69
|
end
|
56
70
|
end
|
57
71
|
|
72
|
+
# Infers the type of field to render based on the field name.
|
73
|
+
#
|
74
|
+
# @param [String, Symbol] the name of the field
|
75
|
+
# @return [Symbol] the inferred type
|
58
76
|
def infer_type(field_name)
|
59
77
|
case field_name
|
60
78
|
when :email, :time_zone
|