On Oct 13, 2014, at 10:34 PM, Khoa Nguyen <huu.khoa.ngu...@gmail.com> wrote:
> 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 > <form ...> > ... > <input name="object[bam]" type="text"> > </form> > > > The assumption has a limitation that content must not contain another form > element. [w3 > spec](http://www.w3.org/TR/2011/WD-html5-20110525/association-of-controls-and-forms.html#association-of-controls-and-forms) > defines a set of attributes on input tags to associate themselves to their > form. > > > # decoupled control and its form > <form id="flexible"...> > </form> > # control input can be placed outside of form tag > # but still be associated to its form > <input form="flexible" name="object[bam]" type="text"> > > > 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 :) 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
signature.asc
Description: Message signed with OpenPGP using GPGMail