Plugins - LabelHelper

StarAdd to favorites

LabelHelper

Rails has no helper for label tags, which are important accessibility/usability features of forms. You shouldn’t have to repeat yourself when writing labels for things: currently you need to do:

  <% form_for(:post, ...) do |f| %>
    < label for="post_title">Title</ label>
    <%= f.text_field(:title) %>
    < label for="post_body">Body</ label>
    <%= f.text_area(:body) %>
  <% end %>

(Ignore the spaces in the label tags - they don’t seem to appear if I leave the spaces out and using entities doesn’t work either.)

Whereas I’d rather not repeat myself over and over…

  <% form_for(:post, ...) do |f| %>
    <%= f.label(:title) %>
    <%= f.text_field(:title) %>
    <%= f.label(:body) %>
    <%= f.text_area(:body) %>
  <% end %>

This plugin lets you do this by adding a label method to ActionView::Helpers::FormHelper. You can also use the FormBuilder style as shown above. See the docs for that module for more details.

License

Copyright © 2007 James Coglan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

James Coglan

http://blog.jcoglan.com/labelhelper/

http://svn.jcoglan.com/labelhelper/trunk/label_helper

Rails' (MIT)

  • Currently 3.2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

View Extensions

Tags

Comments

Add a comment

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?