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

Ticket #7705 (closed enhancement: incomplete)

Opened 1 year ago

Last modified 1 year ago

[PATCH] FormTagHelper - remove []s from ids?

Reported by: Catfish Assigned to: core
Priority: normal Milestone: 1.x
Component: ActionPack Version: edge
Severity: minor Keywords:
Cc:

Description

I often have a use for form tags looking something like the following:

<%= text_field_tag "scene[inputs][1]", "blah" %>

which generates

<input id="scene[inputs][1]" name="scene[inputs][1]" type="text" value="blah"

Which works fine, but it niggles me that the generated html is no longer valid - []'s aren't allowed in ids. The workaround is to always specify the id:

<%= text_field_tag "scene[inputs][1]", "blah", :id => 'scene_inputs_1' %>

which seems ugly & unnecessary.

Is there any interest in patching FormTagHelper so that it automatically changes the id to the underscored form? This would match the behaviour from FormHelper, and form-submitted parameters would continue to function exactly the same (obviously, since they're generated from the name rather than id), but would unfortunately be backwards incompatible with client-side code (eg any javascript or css that uses the form tags' ids).

If there is interest, I'm happy to come up with a patch. If not, I'll carry on monkeypatching.

Attachments

ticket7705.patch (0.6 kB) - added by crayz on 06/04/07 23:53:54.

Change History

03/12/07 11:06:56 changed by Catfish

Is that a wontfix, then?

05/24/07 20:03:16 changed by josh

Catfish, checkout the :index feature and avoid hard coding the [].

Close as a won't fix once you'll got it down.

05/26/07 13:21:26 changed by Catfish

I must be missing something - what :index feature?

05/26/07 14:24:03 changed by josh

form_for :scene do |f|
  f.text_field :inputs, :index => 1
end

<input id="scene_1_inputs" name="scene[1][inputs]" size="30" type="text" />

05/29/07 15:17:16 changed by Catfish

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

There was a reason why I had to use text_field_tag rather than text_field, but since I can no longer remember what it was, I'm going to close this...

06/04/07 23:53:54 changed by crayz

  • attachment ticket7705.patch added.

06/04/07 23:54:52 changed by crayz

  • status changed from closed to reopened.
  • type changed from defect to enhancement.
  • resolution deleted.
  • summary changed from FormTagHelper - remove []s from ids? to [PATCH] FormTagHelper - remove []s from ids?.

I agree with the original sentiment, that it would be useful to change the whatever_tag helpers to give form IDs that match what's used in the normal form helpers for consistency's sake

I'm attaching a simple patch to text_field_tag that seems to do the trick. any chance in getting this applied to the _tag helpers?

07/26/07 12:21:51 changed by kampers

  • status changed from reopened to closed.
  • resolution set to incomplete.

Closing as incomplete: crayz et al., please extend this patch to all the helpers and add unit tests that cover the changes. The test coverage in FormTagHelper is bad enough as it is :) We'll also need some API documentation additions.

Please reopen this once that's ready for a review and we'll look at getting it verified. Thanks!