ravecat
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)
Trending in Questions
Other Trending Topics
Latest Phoenix Threads
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
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #phoenix_html
- #elixirconf-us
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming












Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Zurga
You pass can pass the id of the language as the second item of the option tuple. Then you use
put_associn the changeset function.ravecat
Thank you for your response
Thats works for for standart select form, it’s first advice which I hear when I show a field like this. Could you explain what field should process with
put_assoc? And where is it should process (form, changeset)?we can skip complex
comboboxmechanics and just use multiselect from core componentsform represent changeset, where I prepare data for multiselect
project changeset
project relates with languages through locales schema
After choose another select options I’ve got error, because I work with language id, but projects expect locale as map