Working Example of Phoenix Built in Form Component

From ElixirBlocks
Revision as of 18:59, 18 October 2023 by Admin (talk | contribs)
Jump to: navigation, search



defmodule AppWeb.PageLive do
   use AppWeb, :live_view  
   def mount(_params, _session, socket)  do


      {:ok, assign(socket, form: to_form(%{}, as: :my_form))}

   end

   def handle_event("save", params, socket) do
    {:noreply, socket}
   end

   def render(assigns) do
     ~H"""
        <.form for={@form} phx-change="validate" phx-submit="save">
        <.input type="text" field={@form[:username]} />
        <.input type="email" field={@form[:email]} />
           <button>Save</button>
        </.form>
	 """ 
   end

end