This project is archived and is in readonly mode.

#429 ✓wontfix
Edd Morgan

Support for HTML Class String in options_for_select

Reported by Edd Morgan | June 16th, 2008 @ 03:15 PM

A problem I came across while trying to add class names for options was that it just couldn't be done cleanly, from what I could see. In the spirit of keeping views clean, this patch adds the ability to specify a third element in the option container to generate a class name. For example (from docs):

options_for_select([["Dollar", "$", "american"], ["Kroner", "DKK", "danish"]])
#=> <option value="$" class="american">Dollar</option>\n<option value="DKK" class="danish">Kroner</option>

Comments and changes to this ticket

  • Tarmo Tänav

    Tarmo Tänav June 18th, 2008 @ 04:29 AM

    I don't have an opinion on wether this feature is needed but the patch seems to be using tabs for indenting, these should be replaced with spaces.

  • Chris Barnett

    Chris Barnett June 18th, 2008 @ 07:54 AM

    I don't think this is the best way to fix this problem. What happens when you want to specify the 'id', 'lang', 'style', or 'title' attributes?

    Is there a more general solution?

  • Edd Morgan

    Edd Morgan June 18th, 2008 @ 04:14 PM

    I considered just adding support for an array of hashes as the container but it seems that if one wanted to construct an array of hashes for this, they may as well just iterate their own string of option tags. The class attr seemed to be the one that would be used more often.

    What are everyone's thoughts of adding support for a collection of hashes for each option item?

  • Pratik

    Pratik August 21st, 2008 @ 12:18 PM

    • State changed from “new” to “wontfix”
    • Tag set to actionpack, helper, patch

    I don't think this functionality belongs in core. You should try to pluginize it and see if it's widely used. Also, you can get opinions of others on core mailing list.

    Thanks!

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages