The If Works This dirt was a building before

Another super-tiny 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
    git://github.com/jcoglan/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.


8 Comments

Well… I am not sure if I really got what you are trying to accomplish, but you can access the different input type via css selectors.

input[type=text], input[type=checkbox], … and so on. So there is no real need for attaching a class attribute to all of them.

Posted by Maximilian Schulz on 18 May 2008 @ 12pm

In general, yes you can do that. Most browsers and JS libraries will support that syntax. As far as I know, it does not work in IE6, which was pretty much the motivation for adding class names.

Posted by James Coglan on 18 May 2008 @ 12pm

[...] 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 [...]

Posted by Ajaxian » classy_inputs: Rails plugin to add autoclass names on 21 May 2008 @ 2pm

Thank god someone has made this plugin. I HATE having to add classes to inputs just so I can style them for the luddite IE6 users.

Thanks for this plugin.

Posted by Jim Neath on 22 May 2008 @ 8am

Hasn’t this plugin been made at least 3 or 4 times before. If you check the various plugin archives you will seem them. Been using them for quite some time now.

Posted by Eric Anderson on 22 May 2008 @ 12pm

Eric: quite possibly. But, it’s one of those things that’s so easy to write that I didn’t even bother spending the time to find out if anyone already did it.

Posted by James Coglan on 22 May 2008 @ 4pm

Thanks! Great idea. It’ll make things just a bit cleaner.

Posted by Charlie on 22 May 2008 @ 10pm

Lovely. I too hate having to put class-attributes on every damn input.

Yet another place where IE 6 holds the world back from moving forward.

Posted by Mikkel on 9 June 2008 @ 3pm

Leave a Comment