Skip to content

Conversation

igorbernstein
Copy link
Contributor

This addresses #2659. It allows for nesting of has_many widgets in inputs & other has_many blocks.

The problem that this fixes is that the has_many widget introduces a extra element into Formtastic's fieldset/ol/li hierarchy, which works fine when the has_many is called at the top level, but breaks when its nested in an inputs block. The reason this happens is that formtastic wraps its fieldsets in an li element when it detects that its already in an inputs block. Formtastic's rationale for this behavior is that if we are in an inputs block, then the parent must an ol element, whose children must be lis. However in the case of a has_many, the parent will be a div.

This patch fixes this behavior by pushing the wrapping li element up around the has_many div instead of the has_many's inputs.

TODO:

  • fix up the css (which I could use help with)

@shekibobo
Copy link
Contributor

I looked at this PR, and while it no longer prematurely breaks out of tags on nested has_many, it still doesn't properly insert newly added has_many > has_many fieldsets in the right place:

<form>
  <fieldset class="inputs" />
  <div class="has_many questions">
    <fieldset class="inputs has_many_fields" />
    <fieldset class="inputs has_many_fields">
      <ol>
        <li class="input" />
        <li class="input" />
        <div class="has_many options" />
      </ol>
    </fieldset>
  </div>
  <fieldset class="actions" />
</form>

So, in has_many > has_many, we still get the issue where the fieldset index is off by the number of records originally rendered on page load.

I have proposed a new, consistent structure for has_many forms over in #2659. Let me know what you think, and if it's even possible.

@shekibobo
Copy link
Contributor

I think, in the case of has_many > has_many, we also need to update the html that gets inserted, and update the javascript to tell it where to look for and insert nested fieldsets in this case.

@igorbernstein
Copy link
Contributor Author

@shekibobo thanks for playing with this. You are right, I'll try to fix it up at some point over the weekend

@igorbernstein
Copy link
Contributor Author

superseded by #2679

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants