ravecat
Select field for multiple association
How can I implement a form with m2m field (select shown in the screenshot)?
I would like to emphasize that this is not a dynamic form, an example of which can be found in the repository GitHub - LostKobrakai/one-to-many-form: Example repo for blogpost · GitHub, but it’s a field.
I also know about the possibility of linking via put_assoc in the documentation, which fits this case (Adding tag to a post Ecto.Changeset — Ecto v3.14.0), but it doesn’t mention anything about form implementation.
I also know about live_select, phx-multi-select, etc, It isn’t about component implementation
It’s about matchig schema to form
schema "projects" do
field :name, :string
field :description, :string
has_many :locales, Locales, on_replace: :delete
belongs_to :team, Team
belongs_to :base_language, Language
many_to_many :languages, Language,
join_through: Locale,
on_replace: :delete
timestamps type: :utc_datetime
end
and make multi selection for locales field. I don’t understand, what do I have to work with? Language labels, id languages?
Implemented this via virtual fields, but it seems like I’m doing it wrong
- There is a Project that is linked to Languages through an intermediate table runa/lib/domains/projects/project.ex at 6cced23a560c0780391c8268563d587bda347290 · ravecat/runa · GitHub
- Passing virtual field to form fields runa/lib/application/live/project/form.ex at 6cced23a560c0780391c8268563d587bda347290 · ravecat/runa · GitHub and processed during validation in the same component.
- in the changset for the form I already bind by real fields runa/lib/domains/projects/project.ex at 6cced23a560c0780391c8268563d587bda347290 · ravecat/runa · GitHub
it seems that this approach complicates and contains the issues and could be done more simply (edited)
First Post!
Zurga
You pass can pass the id of the language as the second item of the option tuple. Then you use put_assoc in the changeset function.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









