How to Use the Built In Generated Modal: Difference between revisions
From ElixirBlocks
(Created page with "{{In_progress}}") |
No edit summary |
||
Line 1: | Line 1: | ||
{{In_progress}} | {{In_progress}} | ||
<source> | |||
defmodule AppWeb.PageLive do | |||
use AppWeb, :live_view | |||
def mount(_params, _session, socket) do | |||
{:ok, | |||
assign(socket, | |||
notes: "We are the world" | |||
)} | |||
end | |||
def handle_event("submit-modal-form", params, socket) do | |||
# Create Record | |||
IO.inspect(params) | |||
{:noreply, redirect(socket, to: "/")} | |||
end | |||
def render(assigns) do | |||
IO.inspect(assigns) | |||
~H""" | |||
<%= for id <- 1..5 do %> | |||
<.modal id={"notes-modal-#{id}"}> | |||
<form phx-submit="submit-modal-form"> | |||
<input type="text" name="some-form-item" value={@notes} /> | |||
<input type="submit" phx-click={hide_modal("notes-modal-#{id}")} /> | |||
</form> | |||
</.modal> | |||
<div phx-click={show_modal("notes-modal-#{id}")}>Click item <%= id %></div> | |||
<% end %> | |||
""" | |||
end | |||
end | |||
</source> |
Latest revision as of 18:44, 20 June 2023
This page is in progress
defmodule AppWeb.PageLive do use AppWeb, :live_view def mount(_params, _session, socket) do {:ok, assign(socket, notes: "We are the world" )} end def handle_event("submit-modal-form", params, socket) do # Create Record IO.inspect(params) {:noreply, redirect(socket, to: "/")} end def render(assigns) do IO.inspect(assigns) ~H""" <%= for id <- 1..5 do %> <.modal id={"notes-modal-#{id}"}> <form phx-submit="submit-modal-form"> <input type="text" name="some-form-item" value={@notes} /> <input type="submit" phx-click={hide_modal("notes-modal-#{id}")} /> </form> </.modal> <div phx-click={show_modal("notes-modal-#{id}")}>Click item <%= id %></div> <% end %> """ end end