diff --git a/example_project/lib/example_web/components/layouts/app.html.heex b/example_project/lib/example_web/components/layouts/app.html.heex index 910c542..fcb3968 100644 --- a/example_project/lib/example_web/components/layouts/app.html.heex +++ b/example_project/lib/example_web/components/layouts/app.html.heex @@ -1,4 +1,5 @@
+ <.flash_group flash={@flash} /> <%!-- Main content area --%> diff --git a/example_project/lib/example_web/live/live_form.ex b/example_project/lib/example_web/live/live_form.ex index bae1e43..97a040e 100644 --- a/example_project/lib/example_web/live/live_form.ex +++ b/example_project/lib/example_web/live/live_form.ex @@ -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)} diff --git a/lib/ssr/vite_js.ex b/lib/ssr/vite_js.ex index 6cbadac..73c1352 100644 --- a/lib/ssr/vite_js.ex +++ b/lib/ssr/vite_js.ex @@ -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}