Marmanvii
Value is invalid in multiple_select
I have a multiple_select to select a single medic for an appointment, I managed to show up a list to choose a medic, and when inspecting the element it does have an id as a value, the thing is that when trying to add an appointment it will give an error is invalid in the medic field.
This is my form:
<%= form_for @changeset, @action, fn f -> %>
<%= if @changeset.action do %>
<div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p>
</div>
<% end %>
(...)
<div class="form-group">
<%= label f, :id_medico, class: "control-label" %>
<%= multiple_select f, :id_medico, Enum.map(@medics, &{&1.nombre, Integer.to_string(&1.id)}) %>
<%= error_tag f, :id_medico %>
</div>
(...)
<div class="form-group">
<%= submit "✔", class: "btn btn-primary" %>
<a class="btn btn-danger" href="/appointments" role="button">✖</a>
</div>
<% end %>
and my controller:
def new(conn, _params) do
medics = Clinic.list_medics()
changeset = Clinic.change_appointment(%Appointment{})
render(conn, "new.html", changeset: changeset, medics: medics)
end
Thanks.
First Post!
kokolegorille
Most Liked
kokolegorille
It does not because You use multiselect…
"medic_id" => ["2"],
# but You are expecting an id, like this
"medic_id" => "2",
It returns a list of id, so You need to unwrap and take first ![]()
1
Last Post!
Marmanvii
Popular in Questions
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
Hi everyone,
I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
Other popular topics
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Hi guys, i’m new in the Elixir world, and i have to say, that i love it!
i’m having some problem to understand anonymous functions with ...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
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
- #code-sync
- #javascript
- #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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









