public
Fork of Shadowfiend/awesome_fields
Description: A Rails plugin to improve forms. Includes a better FormBuilder and DRYness for form fields.
Homepage: http://blog.withoutincident.com
Clone URL: git://github.com/gcnovus/awesome_fields.git
switched div class name on error to 'form_line with_errors' to reduce 
duplication in  CSS
gcnovus (author)
Thu Jun 26 23:39:37 -0700 2008
commit  210f29c25124c2b462cb8a01c7dfed5a9f410789
tree    362f5329f5a42518f5a31e78a8672adb7792a7dd
parent  dac28408018d545fd90296ea3935eefa529fe1d6
0
...
44
45
46
47
48
 
 
49
50
51
...
60
61
62
63
 
64
65
66
...
44
45
46
 
 
47
48
49
50
51
...
60
61
62
 
63
64
65
66
0
@@ -44,8 +44,8 @@ error handling to forms. +LinedBuilder+ wraps each input element created by a
0
 call to a field helper in a div of CSS class +form_line+. It also gives it a
0
 label (by default, this contains the humanized name of the field) and, if an
0
 error exists, it provides a nested div within the +form_line+ of CSS class
0
-+field_error+ and the div's class is changed to +form_line_with_errors+. More
0
-details are below.
0
++field_error+ and the div's class is changed to
0
+<tt>form_line with_errors</tt>. More details are below.
0
 
0
 A short example now. Assume there are three fields for a model -- `number',
0
 `date', and `name'. `name' is blank but should not be, and so has an error on
0
@@ -60,7 +60,7 @@ it. The ERB code:
0
 Will yield the HTML output:
0
 
0
  <form ...>
0
- <div class="form_line_with_errors">
0
+ <div class="form_line with_errors">
0
         <div class="field_error">Name should not be blank.</div>
0
         <label for="model_name">Name:</label>
0
         <input type="text" name="model[name]" id="model_name" value="" />
...
18
19
20
21
 
22
23
24
25
26
27
 
 
 
 
 
 
 
 
 
 
 
28
29
30
...
39
40
41
42
 
43
44
45
...
127
128
129
130
 
131
132
133
...
151
152
153
154
 
155
156
157
...
18
19
20
 
21
22
23
24
25
26
 
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
49
50
51
 
52
53
54
55
...
137
138
139
 
140
141
142
143
...
161
162
163
 
164
165
166
167
0
@@ -18,13 +18,23 @@ module AwesomeFields
0
   #
0
   # When producing a field, the field is wrapped with a div whose CSS class is
0
   # +form_line+. If the field has errors, that class is instead
0
- # +form_line_with_errors+. This div is, obviously, a block-level element by
0
+ # <tt>form_line with_errors</tt>. This div is, obviously, a block-level element by
0
   # default, but can be floated or what have you if needed.
0
   #
0
   # == Errors
0
   #
0
   # As mentioned above, if the field has an error, the wrapping div is given the
0
- # +form_line_with_errors+ CSS class instead of the regular +form_line+ class.
0
+ # <tt>form_line with_errors</tt> CSS class instead of the regular +form_line+ class.
0
+ # Recommended CSS looks something like:
0
+ #
0
+ # form div.form_line {
0
+ # ... font, padding, margin, etc.
0
+ # }
0
+ #
0
+ # form div.form_line.with_errors {
0
+ # color: red; <!-- additional formatting for error fields -->
0
+ # }
0
+ #
0
   # Additionally, the error text is placed within the containing +form_line+ div
0
   # within its own div, whose class is +field_error+.
0
   #
0
@@ -39,7 +49,7 @@ module AwesomeFields
0
   #
0
   # The resulting structure of a field with errors is:
0
   #
0
- # <div class="form_line_with_errors">
0
+ # <div class="form_line with_errors">
0
   # <div class="field_error">Field should not be blank.</div>
0
   #
0
   # <label for="model_field">Field:</label>
0
@@ -127,7 +137,7 @@ module AwesomeFields
0
       @template.content_tag( 'div',
0
         (err ? err : '') + label_tag( label, options ) +
0
           super,
0
- :class => err ? 'form_line_with_errors' : 'form_line' )
0
+ :class => err ? 'form_line with_errors' : 'form_line' )
0
     end
0
 
0
     # Produces a submit button wrapped in a div of class +form_buttons+. The
0
@@ -151,7 +161,7 @@ module AwesomeFields
0
 
0
       @template.content_tag 'div',
0
         (err ? err : '') + label_tag(attr, options) + content_gen.call + after,
0
- :class => (err ? 'form_line_with_errors' : 'form_line')
0
+ :class => (err ? 'form_line with_errors' : 'form_line')
0
     end
0
 
0
     # Produces the appropriate label tag for the given attribute, including

Comments

    No one has commented yet.