Skip to content

Documentation on using Form bindings with many-to-many or belongs-to fields lacking #3197

@ponychicken

Description

@ponychicken

In many applications you have some kind of belongs-to or many-to-many associations.
Like a blog post which has many categories, and each category has many blog posts.

It is straightforward to figure out how to make a <.input type="select"> for an Enum,
such as

<.input
          field={@form[:status]}
          type="select"
          label="Status"
          options={Ecto.Enum.values(Post, :status)}
/>

The same approach fails when trying to add a similar dropdown field to select the categories

<.input
          field={@form[:categories]}
          type="select"
          label="Categories"
          options={get_categories()}
/>

with ** (Protocol.UndefinedError) protocol Phoenix.HTML.Safe not implemented for %Category{...

Since this is a common pattern, I would suggest to add some paragraph into guides/client/form-bindings.md to explain the prefered way to solve this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions