merb_form_fields 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README +25 -0
- data/Rakefile +1 -1
- data/lib/merb_form_fields/form_field_builder.rb +18 -1
- metadata +2 -2
data/README
CHANGED
@@ -3,6 +3,10 @@ merb_form_fields
|
|
3
3
|
|
4
4
|
A plugin for the Merb framework that provides a Form Builder that wraps each of your fields.
|
5
5
|
|
6
|
+
to install
|
7
|
+
dependency "merb_form_fields"
|
8
|
+
|
9
|
+
|
6
10
|
It provides validation on the wrapper (adds a class), and will insert the error message automatically.
|
7
11
|
|
8
12
|
= form_with_fields_for(@user) do
|
@@ -29,6 +33,9 @@ Customize Fields with the :field option (takes a hash)
|
|
29
33
|
Customize the error message with the :error option (overrides the default model error)
|
30
34
|
= text_field :first_name, :error => "Bzzzzt... wrong!"
|
31
35
|
|
36
|
+
Customize the note for the field
|
37
|
+
= text_field :first_name, :note => "Give us your first name"
|
38
|
+
|
32
39
|
|
33
40
|
All render options are easily configurable via Merb::Plugins.config[:merb_form_fields]
|
34
41
|
|
@@ -61,6 +68,24 @@ Field Error Class
|
|
61
68
|
e.g. <div class="field error ...">...</div>
|
62
69
|
if you set it to "invalid", it would render as <div class="field invalid ...">...</div>
|
63
70
|
|
71
|
+
Note Tag
|
72
|
+
---------
|
73
|
+
Merb::Plugins.config[:merb_form_fields][:note_tag]
|
74
|
+
defaults to :span
|
75
|
+
|
76
|
+
this defines which tag is used for the note wrapper.
|
77
|
+
e.g. <span class="note">...</span>
|
78
|
+
if you set it to :em, it would render as <em class="note ...">...</em>
|
79
|
+
|
80
|
+
|
81
|
+
Note Class
|
82
|
+
------------
|
83
|
+
Merb::Plugins.config[:merb_form_fields][:note_class]
|
84
|
+
defaults to "note"
|
85
|
+
|
86
|
+
this defines the class used by default for the note wrapper.
|
87
|
+
e.g. <span class="note">...</span>
|
88
|
+
if you set it to "explain", it would render as <span class="explain">...</span>
|
64
89
|
|
65
90
|
Error Message Tag
|
66
91
|
------------------
|
data/Rakefile
CHANGED
@@ -19,6 +19,17 @@ module MerbFormFields
|
|
19
19
|
def field_class
|
20
20
|
Merb::Plugins.config[:merb_form_fields][:field_class] || "field"
|
21
21
|
end
|
22
|
+
|
23
|
+
# This tag wraps the note
|
24
|
+
def note_tag
|
25
|
+
Merb::Plugins.config[:merb_form_fields][:note_tag] || :span
|
26
|
+
end
|
27
|
+
|
28
|
+
# This is the default note class
|
29
|
+
def note_class
|
30
|
+
Merb::Plugins.config[:merb_form_fields][:note_class] || "note"
|
31
|
+
end
|
32
|
+
|
22
33
|
|
23
34
|
# whether or not to add the field_type class
|
24
35
|
def add_field_type_class?
|
@@ -39,6 +50,7 @@ module MerbFormFields
|
|
39
50
|
# ---------------------------------------------
|
40
51
|
def field_wrapper(field_type, attrs = {})
|
41
52
|
field_options = attrs.delete(:field) || {}
|
53
|
+
note = attrs.delete(:note)
|
42
54
|
error_override = attrs.delete(:error)
|
43
55
|
|
44
56
|
# build inner field html (using the passed in block)
|
@@ -57,9 +69,14 @@ module MerbFormFields
|
|
57
69
|
css_class << " #{error_class}"
|
58
70
|
end
|
59
71
|
|
72
|
+
# build note
|
73
|
+
unless note.blank?
|
74
|
+
note_wrapper = tag note_tag,
|
75
|
+
note, :class => note_class
|
76
|
+
|
60
77
|
# build field
|
61
78
|
tag field_tag,
|
62
|
-
"#{inner_html}#{field_error_message(@obj, attrs[:method], error_override)}",
|
79
|
+
"#{inner_html}#{field_error_message(@obj, attrs[:method], error_override)}#{note_wrapper}",
|
63
80
|
field_options.merge(:class => css_class)
|
64
81
|
end
|
65
82
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merb_form_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacques Crocker
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-02-
|
12
|
+
date: 2009-02-24 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|