Button Labels

Posted by Gregg Kellogg Tue, 24 Oct 2006 02:22:00 GMT

I checked in the button-labels plugin. I was frustrated when trying to create a form with multiple radio-buttons and no way to tell them apart. Basically, if the :label option is passed to radio_button, it calls content_tag() instead of tag() and uses the label as the content.

radio_button("post", "title", "Goodbye World", :label => "Goodby World")

<input id="post_title_goodbye_world" 
     name="post[title]" 
     type="radio" 
     value="Goodbye World">
  <label for="post_title_goodbye_world>
    Goodby World
  </label>
</input>

The plugin is managed on ruby_forge. Rdoc is available.

Entered some time ago as a bug #4627.

Gregg Kellogg

Posted in  | 3 comments | no trackbacks

Comments

  1. Avatar Gregg Kellogg said 121 days later:

    Updated package to support labels for Check Boxes as well as Radio Buttons.

  2. Avatar Jatinder Singh said 165 days later:

    Beautiful plugin. thanks! one question: why did you not consider doing(labelling) similarly for input/select fields?

  3. Avatar Gregg Kellogg said 184 days later:

    It would be a simple extension to add this to other methods, such as input and select. However, the primary motivation for doing this for radio buttons and checklists is that they are are implemented using the tag() rather than content_tag() method (my change makes them content_tag if a label is specified). Given that select is based on content_tag, a the label can simply be added as part of the content. The input tag, however, is based on tag, and so could benefit from supporting a :label option. I just haven’t found it necessary when creating forms.

Trackbacks

Use the following link to trackback from your own site:
http://kellogg-assoc.com/articles/trackback/5

(leave url/email »)

   Comment Markup Help Preview comment