Feature Request: form associated element

As far as I know, Rails doesn’t generate form attribute for input control tags because it’s assumed that form content is captured and rendered within a block.

typical rails form usage

<%= form_for(object) do |f| %> <%= f.text_field :bam %> <% end %>

generates

...

The assumption has a limitation that content must not contain another form element. w3 spec defines a set of attributes on input tags to associate themselves to their form.

decoupled control and its form

# control input can be placed outside of form tag # but still be associated to its form

Will Rails support auto generation of form attribute on input controls, that are outside of form tag? Is this feature on the roadmap?

Quick hacks are most welcomed :slight_smile:

Auto-generation seems unlikely - the ID of every form on the page would have to be stashed someplace template-wide and then the right one would need to be picked. That’s not even counting how forward references would need to work (form elements that precede the form in the DOM).

Haven’t tried it, but does explicitly adding form: ‘whatever_your_form_id_is’ to the html_options for an input tag do the right thing?

—Matt Jones

Yes it does work, you can pass any html attribute you want and it will be use as-is. But I think he’s asking if he can use form_for variant of helpers outside of the form_for block.

So you can use *_tag helpers outside of a form_for and set ‘form’ attributes by hand but you’ll also need to handle value attribute.