Skip to content
Labelled Form Builder Plugin for Rails
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
test
MIT-LICENSE
README.rdoc
Rakefile
init.rb

README.rdoc

Labelify

A form builder plugin for form_for and family which automatically adds labels to the input fields and places error messages, if they exists for that field, next to the label.

Installation

This is a Rails plugin and can be installed with:

ruby script/plugin install -f git://github.com/remvee/labelify.git

Usage

Use Labelify.labelled_form_for like you would use form_for. You don't need to make labels, they will be inserted for you automatically. Label creation can be manipulated by giving label as an option to a field method; false will suppress label rendering and a string will override the fieldname.

Error messages for the give field will be included in the labels right after the field name. Base errors will appear directly before the form tag.

Unlike form_for, labelled_form_for will pass all calls to the template. This means not only the field helpers can be accessed but also home grown fields helpers, as long as they accept the object_name, object_method, options arguments.

The Labelify helper methods are automatically included. To use this builder as the default form builder, use the following:

ActionView::Base.default_form_builder = Labelify::FormBuilder

Example

This form:

<% labelled_form_for :user, :url => {:action => 'profile'} do |f| -%>
  <%= f.text_area('description') %>
  <%= f.password_field('password') %>
  <%= f.submit('Store') %>
<% end -%>

with an error on the description field yields:

<form action="/profiel" method="post">
  <div class="field">
    <label for="user_description">
      <span class="field_name">Description</span>
      <span class="error_message">can't be blank</span>
    </label>
    <div class="fieldWithErrors">
      <textarea id="user_description" name="user[description]"></textarea>
    </div>
  </div>
  <div class="field">
    <label for="user_password">
      <span class="field_name">Password</span>
    </label>
    <input id="user_password" name="user[password]" value="" type="password"/>
  </div>
  <input class="submit" value="Store" type="submit"/>
</form>

Copyright

Copyright © 2006, 2007, 2008 R.W. van 't Veer

Something went wrong with that request. Please try again.