Proposal: Tracking forms by id

In the rails application that I work on, we have a number of use cases for forms where it doesn’t make sense to wrap all of the inputs inside the form element (or where there are some forms that would be nested inside another form. It’s somewhat trivial to use dom_id and create an id for the form, and use the form attribute on the form inputs which is the way to accomplish this within the html5 spec. However, while dom_id provides a nice way to provide some rails around naming ids, there’s not a good way to “define” these sorts of dependencies on the form inputs that may live in separate view partials, and often dom_id(my_model) is used on some higher container/turbo frame. Its seems like there could be some sort of convention that would enable using a view helper to track form id’s in the view_context.

Something like:

# somewhere in ActionView
@forms = []
def form_id(obj)
  id = dom_id(obj, :form)
  @forms << id

form_with could just do this by default

<% form_with model: do... %>
<%= input_tag :foo, {}, { form: form_id(obj) } %>