Class: MirFormBuilder

Inherits:
ActionView::Helpers::FormBuilder
  • Object
show all
Includes:
ApplicationHelper
Defined in:
lib/mir_form_builder.rb

Overview

Configuration

Configure your application to default to the custom form builder

In app/controllers/application_controller.rb:

class ApplicationController < ActionController::Base
  ActionView::Base.default_form_builder = MirFormBuilder

Usage

Default form field with label:

<%= f.text_field :last_name -%>

Returns:

<fieldset>
  <label for="user_last_name">Last Name</label><br />
  <input id="user_last_name" name="user[last_name]" size="30" type="text" />
</fieldset>

Form field with custom label:

<%= f.text_field :first_name, :label => 'Custom' -%>

Returns:

<fieldset>
  <label for="user_first_name">Custom</label><br />
  <input id="user_first_name" name="user[first_name]" size="30" type="text" />
</fieldset>

Form field with no label

<%= f.text_field :search, :label => false -%>

Returns:

<input id="search" name="search" size="30" type="text" />

Form field with inline help (? icon which reveals help content when clicked):

<%= f.password_field :password %>

Returns:

<fieldset>
  <label for="password">Password: <img src="/images/icons/help_icon.png"
  onclick="$('password_help').toggle();" class='inline_icon' /></label><br />
  <div class="inline_help" id="password_help" style="display: none;">
    <p>Here are some detailed instructions on valid passwords.</p>
  </div>
  <input id="user_password" name="user[password]" size="30" type="password" />
</fieldset>

Form field with instructions (show immediately below the label):

<%= f.password_field :password_confirmation %>

Returns:

<fieldset>
  <label for="password_confirmation">
    Confirm Password:
    <span class="instructions">Enter your password again to confirm.</span>
  </label><br />
  <input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" />
</fieldset>

Check box with label in addition to checkbox value text

(E.g. ‘Foo’ appears above the checkbox, and ‘Something’ next to it):

<%= f.check_box :foo, :inline_label => 'Something' -%>

Returns:

<fieldset>
  <label for="user_foo">Foo</label><br />
  <input name="user[foo]" type="hidden" value="0" />
  <input id="user_foo" name="user[foo]" type="checkbox" value="1" />
  <label class="inline" for="user_foo">Something</label><br style='clear: both;'/><br />
</fieldset>

Don’t wrap fields in a fieldset

<%= f.text_field :query, :label => 'Search terms:', :fieldset => false -%>

Returns

<label for="search_terms_query"><br />
<input id="search_terms_query" name="search_terms_query" size="30" />

Troubleshooting

If you’re seeing double form labels, it’s because you still have <%= label -%> elements in your forms.

Constant Summary

Constants included from ApplicationHelper

ApplicationHelper::SELECT_PROMPT, ApplicationHelper::SELECT_PROMPT_OPTION

Method Summary

Methods included from ApplicationHelper

#action?, #array_to_lines, #checkmark, #controller?, #crud_links, #crud_links_for_nested_resource, #legend_block, #legend_tag, #meta_description, #meta_keywords, #models_for_select, #obfuscated_link_to, #options_for_array, #required_field_helper, #select_tag_for_filter, #sort_link, #tab_body, #tab_tag, #tabset, #tag_for_collapsible_row, #tag_for_collapsible_row_control, #tag_for_label_with_inline_help, #tag_for_label_with_instructions