Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #362 (closed enhancement: wontfix)

Opened 4 years ago

Last modified 1 year ago

text_field should take :label option

Reported by: tomasj Assigned to: David
Priority: low Milestone: 1.x
Component: ActionPack Version: edge
Severity: normal Keywords: text_field label
Cc: myles@bgit.com.au

Description

When making a text_field, one should be able to supply a :label option -- which would result in <label>Description</label> being created prior to the <input type="text" ... />

An alternative would be :label_with_br which would result in <label>Description</label><br />

Attachments

label_option_for_input_fields.diff (6.1 kB) - added by okax@gmx.de on 11/16/05 14:24:09.
[PATCH] new option "label" will create a label tag for the input field

Change History

12/21/04 18:00:13 changed by anonymous

No other input helper generates two actual elements, why should this? At the same time, for checkboxes and radiobuttons you want the labels on the right side, this would lead to a lot of complex option for something you can do with

content_tag("label", "my label", :id => "myid")

or make your own helper

label_for(object, record)

12/22/04 00:53:54 changed by tomasj

It's not true that no other input helper generates two actual elements. check_box, for instance, generates a hidden input variable as well, besides the actual input type checkbox.

The answer to your question of "why?", is convenience.

03/01/05 06:01:45 changed by bitsweat

  • severity changed from normal to enhancement.
  • milestone deleted.

03/05/05 02:37:00 changed by nzkoz

  • milestone set to 1.x.

I'm setting the milestone of this ticket to 1.x, this means that the earliest it will be implemented is after 1.0. If you feel this functionality should be included in the 1.0 release please email the developers list to discuss it

05/30/05 19:32:20 changed by anonymous

Having the break tag after a label tag assumes that the author wants the input box on the next line after the label content. This is not always the case. Besides, layout of labels and inputs can be handled via CSS - no need for the <br /> tag.

08/02/05 20:49:52 changed by anonymous

  • cc set to myles@bgit.com.au.
  • version changed from 0.9.1 to 0.13.1.

Could we get label_for or label_tag into 1.0?

For example here's a pretty common input tag:

<%= text_field "account", "email %>

This will automatically generate an id of 'account_email' eg:

<input type="text" id="account_email" ... />

So now if I want to add a label (that doesn't wrap the input element) I have to type:

<label for="account_email">Some label</label> <%= text_field "account", "email" %>

This gets really annoying when your copying and pasting because you can just copy/paste the arguments for the text field into the <label for="..." part, you have to manually add that underscore and remove the quotes.

I use a small helper in my app that looks like this:

def label_tag (name, object, method=false)
    if method
      id = "#{object}_#{method}"
    else
      id = object
    end
    "<label for=\"#{id}\">#{name}</label>"
  end

maybe something like that could be included?

08/02/05 20:52:38 changed by nzkoz

Sure,

If you open another ticket for label tag, we can look into it. However the easiest way to get it included is to attach a patch along with it ;)

11/16/05 14:24:09 changed by okax@gmx.de

  • attachment label_option_for_input_fields.diff added.

[PATCH] new option "label" will create a label tag for the input field

02/13/06 00:14:04 changed by BobSilva

I tend to disagree that Rails should provide this functionality attached to the text_field helper. The label_for isn't a bad idea since it can take the model.field arguments of the text field and generate the right for= name.

01/17/07 21:00:20 changed by jarkko

  • priority changed from normal to low.
  • version changed from 0.13.1 to edge.
  • milestone changed from 1.2 to 1.x.

I agree with BobSilva. This is a clear case for a custom form builder or a plugin that provides one. As much as I love the label tag, I don't think the plain vanilla text_field should include it. If it would, then it would need to be also in text_area, select stuff etc, etc.

Creating a helper of its own for label is a really good idea, though, in fact so good that I created a placeholder ticket (#7139) for it and will submit the patch as soon as I get up next morning.

(follow-up: ↓ 11 ) 01/17/07 21:16:22 changed by smeade

jarkko - IMHO I agree with you on the label tag helper and look forward to the patch

(in reply to: ↑ 10 ) 01/17/07 21:28:18 changed by jarkko

Replying to smeade:

jarkko - IMHO I agree with you on the label tag helper and look forward to the patch

smeade: I uploaded the patch for the helper, take a look (#7139) if you're interested. It doesn't have tests and docs yet, I need a bit sleep before I post an updated patch. It seems to work fine, though.

05/22/07 19:39:27 changed by josh

  • status changed from new to closed.
  • resolution set to wontfix.

Write your own custom form builder, as the position of the label is debatable.