Skip to content

Commit

Permalink
fix decoding of form values
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmarcon committed Dec 3, 2023
1 parent 6bc7391 commit b387ea6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/support/live_select_web/live/showcase_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,8 @@ defmodule LiveSelectWeb.ShowcaseLive do
"change" ->
params =
update_in(params, ~w(my_form city_search), fn
nil -> nil
selection when is_list(selection) -> Enum.map(selection, &Jason.decode!/1)
selection -> Jason.decode!(selection)
selection when is_list(selection) -> Enum.map(selection, &decode/1)
selection -> decode(selection)
end)

assign(socket, :live_select_form, to_form(params["my_form"], as: :my_form))
Expand Down Expand Up @@ -410,6 +409,13 @@ defmodule LiveSelectWeb.ShowcaseLive do
{:noreply, socket}
end

defp decode(value) do
case Jason.decode(value) do
{:ok, value} -> value
{:error, _} -> value
end
end

defp live_select_assigns(changeset) do
Settings.live_select_opts(changeset.data)
|> Keyword.update(:disabled, !changeset.valid?, fn
Expand Down

0 comments on commit b387ea6

Please sign in to comment.