How to Use phx-change with a Select Element in Phoenix

From ElixirBlocks
Jump to: navigation, search

This page is in progress



defmodule AppWeb.GroupLive do
  use AppWeb, :live_view
  alias App.TestBeds
  alias App.Groups


  def mount(_params, _session, socket) do
    {:ok, assign(socket, testbeds: TestBeds.list_testbeds(), groups: Groups.list_groups())}
  end


  def handle_event("select-group", params, socket)  do  

       IO.inspect params

       {:noreply, socket}
  end


  def render(assigns) do
    ~H"""
    <div> TestBed Name</div>

   <%= for testbed <- @testbeds do %>
    <div class="name"><%= testbed.name %></div>
      <h2> Select Group </h2>
      <form>
       <select id="group-selection" phx-change="select-group"  name="name">
        <%= for group <- @groups do %>
          <option value= {"#{group.id}"} name={"#{group.id}"}><%=group.name %></option>
      <% end %>
       </select>
     </form>
   <% end %>

   <div>
    
   </div>
    """
  end
end