public
Description: A Rails plugin which extends the form builder and tag helpers for critically awesome labeling capabilities.
Homepage: http://agilewebdevelopment.com/plugins/labeling_form_helper
Clone URL: git://github.com/greatseth/labeling-form-helper.git
100644 67 lines (35 sloc) 3.012 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
= Labeling Form Helper
 
Adds auto-labeling with some custom options to Rails' form helpers by extending ActionView::Helpers::FormBuilder and ActionView::Helpers::FormTagHelper.
 
In these examples, :labeling_form_builder is an instance of LabelingFormBuilder such as you would get using the :form_for helper's :builder option or by setting it as the application default in your environment or other configuration.
  
  
  >> labeling_form_builder.text_field :attr_name
  => <label for="thing_attr_name">Attr name</label><input ... />
  
  >> labeling_form_builder.text_field :attr_name, :label => 'yeah, foo'
  => <label for="thing_attr_name">yeah, foo</label><input ... />
  
  >> labeling_form_builder.text_field :attr_name, :label => false
  => <input ... />
  
  
To ease integration of the _tag helpers, the labeling behavior is off by default unless you at least specify :label => true.
 
  
  >> text_field_tag :attr_name
  => <input ... />
  
  >> text_field_tag :attr_name, :label => true
  => <label for="attr_name">Attr name</label><input ... />
  
  
Wrapping the input can be useful for checks and radios, as well as a style hook of sorts in some situations. The interface shown is identical for the form builder.
 
  
  >> check_box_tag :attr_name, :label => { :wrap => true }
  => <label for="attr_name">Attr name <input ... /></label>
  
  >> check_box_tag :attr_name, :label => { :after => true }
  => <input ... /><label for="attr_name">Attr name</label>
  
  >> radio_button_tag :attr_name, :label => { :wrap => true, :after => true }
  => <label for="attr_name"><input ... /> Attr name</label>
  
  >> radio_button_tag :attr_name, :label => { :wrap => :after }
  => <label for="attr_name"><input ... /> Attr name</label>
  
 
Valid values for the :label option are:
  
  
  * true - This will render with the default auto-labeling behavior. This is only useful for the _tag helpers which act as normal unless the :label option is set.
  * false - This will render the normal behavior i.e. without a label. This is only useful for the LabelingFormBuilder which adds the behavior from this plugin by default.
  * String - Customize the label text, normally the humanized version of the attribute name for the field.
  * Hash - Customize text with :text and the order of the label + input pair and/or whether or not the label wraps the input using :wrap and/or :after. Any other HTML tag attribute options will be applied to the label tag.
  
  
You can easily set the LabelingFormBuilder as the application default using the following expression:
  
  
  >> ActionView::Base.default_form_builder = LabelingFormBuilder
  
    
The LabelingFormTagHelper is enabled by default, but its behavior is not applied to the normal _tag helpers unless you use the :label option.
 
Please label responsibly.
 
CONTRIBUTORS
  
  * Seth Thomas Rasmussen : http://greatseth.com : sethrasmussen@gmail.com
  * Jeremy Kemper : http://bitsweat.net