Wednesday, May 21st, 2008
classy_inputs: Rails plugin to add autoclass names
We all want to use input[type=text] but browser support doesn’t seem to quite be there (IE 6?).
This lead James Coglan down the path of creating a teeny Rails plugin, classy_inputs:
Good lord do I ever hate input tags. (YUI hates them too, but I’ll leave that story for another time). All the different types should really have been different tag names, and they are a total pain to use with CSS. As such, I used to end up doing tedious stuff like adding a :class option to every form element when writing Rails templates. A while back, I tried to patch Rails to get it to do this automatically, but its test suite totally baffled me at the time by applying the classes in some places but not others.
So, a quick plugin to stave off RSI:
script/plugin install
http://svn.jcoglan.com/classyinputs/trunk/classy_inputs
With that installed, any input tag created using a Rails view method will gain a class name matching its type attribute. Maybe I’ll have another stab at patching Rails, but I’m not promising anything.












A nice idea … I usually just add classnames to the enclosing fieldsets … and someday, I’ll take a stab at patching Rails scaffold code to use fieldsets instead of p tags … at least they’re using labels and not spans.
Why would you use a fieldset for a single field and its label?
Fieldsets are for field sets.
With IE6 losing it’s share now, I’ve started to finally adopt CSS selectors to style inputs. On IE6 and worse, you simply do not see them, while on better browsers you get the full eyecandy.
I’m with James on this. I’ve actually been pondering writing a plugin that does the exact same thing as this.
Also I’ve kind of been doing what Gordon has been doing by using jquery to add the class name but that means you have to wait for the dom to load until you can apply the class styles.
If you check the various Rails plugin archives you will find there are at least three or four plugins that do this same thing already. Been using them for quite a while.
eric2: how about posting a link or three?
i’ve also been thinking about doing the same for CakePHP