Every repository with this icon (
Every repository with this icon (
tree c76b8763c2a505af2e5cada9a7af9a9d7995aa41
parent 2a3e11f239e279deda9d0a96b3ecbf4c61f85164
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Wed Sep 03 13:11:03 -0700 2008 | |
| |
README.rdoc | Fri Oct 24 02:27:04 -0700 2008 | |
| |
Rakefile | Fri Oct 24 02:23:55 -0700 2008 | |
| |
init.rb | Mon Oct 22 02:25:44 -0700 2007 | |
| |
lib/ | ||
| |
test/ |
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








