Marmanvii

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

kokolegorille

I guess the problem is in the appointment schema.

Most Liked

kokolegorille

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 :slight_smile:

Last Post!

Marmanvii

Marmanvii

That did the trick, thanks.

Where Next?

Popular in Questions Top

rms.mrcs
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
baxterw3b
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
ovidiubadita
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
jononomo
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
sen
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
komlanvi
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
freewebwithme
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 Top

rms.mrcs
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
vertexbuffer
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
baxterw3b
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
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
stefanchrobot
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement