Skip to content

BelongsTo and HasMany not supported in nested forms #5

@Billiam

Description

@Billiam

I believe that these two field types (and possibly select as well), will not work correctly within nested-has-many fields.

Unlike other fields, which don't bother explicitly passing field values (using the formbuilder instead), these types rely directly on field data to populate selected options:

Example from belongs_to/_form.html.erb

<div class="field-unit__field">
  <%= f.select(field.permitted_attribute) do %>
    <%= options_for_select(field.associated_resource_options, field.selected_option) %>
  <% end %>
</div>
def selected_option
  data && data.id
end

I don't think this is an issue with the nested has many field type, but does show that upstream fields may not play nicely with it.

It seems like it would be safe to override these fields' templates, ex:

<%= f.select(field.permitted_attribute, field.associated_resource_options) %>

but I hesitate to issue a pull request to administrate without knowing the reason these fields are handled differently, or whether the nested has many field represents a supported use case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions