You are here: Browse Railsplugins Labeling Form Helper
= 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:
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
NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly