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 Responses to “Another super-tiny Rails plugin: classy_inputs”

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.

Maximilian Schulz added these pithy words on May 18 08 at 12:08 pm

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.

James added these pithy words on May 18 08 at 12:45 pm

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

Ajaxian » classy_inputs: Rails plugin to add autoclass names added these pithy words on May 21 08 at 2:50 pm

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.

Jim Neath added these pithy words on May 22 08 at 8:30 am

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.

Eric Anderson added these pithy words on May 22 08 at 12:58 pm

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.

James added these pithy words on May 22 08 at 4:05 pm

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

Charlie added these pithy words on May 22 08 at 10:27 pm

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.

Mikkel added these pithy words on Jun 09 08 at 3:36 pm

Leave a Reply