chore: adjust form json parser

This commit is contained in:
Denis Donici 2026-03-06 02:06:09 +02:00 committed by Wout De Puysseleir
parent 251b51b5eb
commit c0c94fb9dc
3 changed files with 12 additions and 3 deletions

View file

@ -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 --%>

View file

@ -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)}

View file

@ -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}