This post originated from an RSS feed registered with Ruby Buzz
by Eric Stewart.
Original Post: Label me, please!
Feed Title: Ponderings On Ruby
Feed URL: http://blog.eric-stewart.com/category/programming-ruby.rss
Feed Description: This is the Ruby related section of Eric Stewart's weblog. These entries will be the commentary of a long time Java/C++ programmer that started exploring Ruby in 2003.
Imagine you are a good web developer. You like following standards, paying attention to usability, and thinking about accessibility while implementing the latest, greatest whiz-bang next-generation web wunder-site. Yes, I’m talking to you!
You have forms somewhere on your site, right. There has to be one somewhere. And you have labels on all of your fields too, right? Of course you do!
Well, label helpers are one of the things left out of Rails up to and including 1.0. It’s easy to imagine why. A label is pretty trivial to write, and if you can’t figure out the necessary for attribute, then all hope is lost. However you’d love to not have to worry about the for wouldn’t you?
Still, there really needed to be some other reason to go to all the trouble to write a form helper. Well, I can think of one. And so I did.
label_helpers plugin for Rails
This plugin adds the helpers label and label_tag. Of course, label_tag is quite trivial, so it’s label that you’ll see the most benefit from.
I happen to work on web sites often where accessibility is of high priority, and so anything I can to do further that effort is a plus. I happened to like the technique described by Derek Feathersone for form error messages.
In a nutshell, this technique and the new helper allow including error messages for validation problems within the label for an inputs. This allows the error message to be grouped with the field title, aiding screen readers as well as visual users. And CSS can be used to position the error portion of the label appropriately.
Of course you can turn the errors off if need be.
It’s still rough around the edges, but working for me so far. Comments are appreciated!
Check out the source from Subversion, or preferable use Rails own script/plugin script to help install it. All you have to do (from the root of your rails project) is: