IE6 is like some slightly slow friend who is very much too big for his age, and sometimes you just plain to forget to invite him to the party.
Attribute Selectors are just about the coolest things there that ever did come to CSS, especially when it comes to submit buttons. Oh, how wonderful to style your form one way, and then have a little special treatment for your submit (or reset) buttons, like this:
input, select, option, textarea {
font: 11px sans serif;
color: grey;
border: thin solid grey;
}
input[type=submit] {
background-color: gray;
color: black;
}
So, in a recent project I was happily coding along, and wouldn’t ya know it, I forgot about my big dumb friend. IE6 has no idea about attribute selectors, the sad sack.
After some sighing, googling, and ranting, I realized that I’d have to code in a class attribute for every single submit button on the site. There’s not that many, but what a pain - and how un-DRY!!
Rails to the rescue. All my submit buttons were generated at some point by the submit_tag helper, so I knew that if I could override that with my own, then I could add the :class => "submit" argument that I needed across my site.
Step 1: find out where submit_tag is defined
Over to the Rails API page and look up submit_tag, I discover that it’s defined in ActionView::Helpers::FormTagHelper.
Step 2: write my own
I want it available to everything in my app, so I fire up my trust gvim and open config/environment.rb and here’s what I append to the very end:
module ActionView
module Helpers
module FormTagHelper
alias_method :orig_submit_tag, :submit_tag
def submit_tag( value, options = {})
orig_submit_tag( value, options.merge( :class => "submit"))
end
end
end
end
And that’s it, now every submit tag in your application will have a class attribute set to "submit". Still not as nice as if all IE6 users upgraded to IE7 or FF tomorrow, but it’s a lot better than trawling through your code changing all the submit buttons.


Comments
There are 2 comments on this post. Post yours →
Good post. It’s always nice when someone blogs about what they had to do to deal with IEsucks, I mean IE6 :)
BTW, you recent project link has a typo… it’s http://phoebcarlyle.com/ and I should be http://phoebecarlyle.com/ ….missing the second e.
hey where did the plugin go if it needs hosting i would be more than happy to host it for you.
Post a comment
Required fields look like this.