mirror of
https://github.com/woutdp/live_svelte
synced 2026-05-24 09:28:21 +00:00
chore: adjust form json parser
This commit is contained in:
parent
251b51b5eb
commit
c0c94fb9dc
3 changed files with 12 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
|||
<div class="drawer">
|
||||
<.flash_group flash={@flash} />
|
||||
<input id="mobile-drawer" type="checkbox" class="drawer-toggle" phx-update="ignore" />
|
||||
|
||||
<%!-- Main content area --%>
|
||||
|
|
|
|||
|
|
@ -56,8 +56,14 @@ defmodule ExampleWeb.LiveForm do
|
|||
changeset = Schema.changeset(%Schema{}, attrs)
|
||||
|
||||
if changeset.valid? do
|
||||
# Successful submit — tell the client to reset, return a clean form.
|
||||
{:reply, %{reset: true}, assign(socket, form: empty_form())}
|
||||
name = attrs["name"] || ""
|
||||
email = attrs["email"] || ""
|
||||
msg = "Info submitted: #{name} (#{email})"
|
||||
# Successful submit — show success toast, tell the client to reset, return a clean form.
|
||||
{:reply, %{reset: true},
|
||||
socket
|
||||
|> put_flash(:info, msg)
|
||||
|> assign(form: empty_form())}
|
||||
else
|
||||
form = changeset |> to_form(as: "form_data", action: :validate)
|
||||
{:reply, %{}, assign(socket, form: form)}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ defmodule LiveSvelte.SSR.ViteJS do
|
|||
@behaviour LiveSvelte.SSR
|
||||
|
||||
def render(name, props, slots) do
|
||||
data = Jason.encode!(%{name: name, props: props, slots: slots})
|
||||
prepared_props = LiveSvelte.JSON.prepare(props)
|
||||
prepared_slots = LiveSvelte.JSON.prepare(slots)
|
||||
data = Jason.encode!(%{name: name, props: prepared_props, slots: prepared_slots})
|
||||
url = vite_path("/ssr_render")
|
||||
params = {String.to_charlist(url), [], ~c"application/json", data}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue