diff --git a/lib/who_need_help_web/form_params.ex b/lib/who_need_help_web/form_params.ex index 3bd982b..93e7083 100644 --- a/lib/who_need_help_web/form_params.ex +++ b/lib/who_need_help_web/form_params.ex @@ -10,10 +10,11 @@ defmodule WhoNeedHelpWeb.FormParams do |> Enum.reject(fn key -> Map.has_key?(data, @live_view_unused_prefix <> to_string(key)) end) - |> MapSet.new(&to_string/1) + |> Enum.map(&to_string/1) + |> Enum.uniq() end - def touched_structured_keys(_params), do: MapSet.new() + def touched_structured_keys(_params), do: [] def drop_unused_structured_fields(%{"structured_data" => data} = params) when is_map(data) do @@ -36,7 +37,7 @@ defmodule WhoNeedHelpWeb.FormParams do field -> key = to_string(field["key"]) - if submitted? or MapSet.member?(touched_keys, key) do + if submitted? or key in touched_keys do [{error_kind(message, key), field_label(field, locale)}] else [] diff --git a/lib/who_need_help_web/live/activity_live/new.ex b/lib/who_need_help_web/live/activity_live/new.ex index 4b8479b..43d3792 100644 --- a/lib/who_need_help_web/live/activity_live/new.ex +++ b/lib/who_need_help_web/live/activity_live/new.ex @@ -13,7 +13,7 @@ defmodule WhoNeedHelpWeb.ActivityLive.New do |> assign(:categories, Catalog.list_categories(:activity)) |> assign(:selected_category, nil) |> assign(:structured_fields, []) - |> assign(:structured_touched_keys, MapSet.new()) + |> assign(:structured_touched_keys, []) |> assign(:structured_submit_attempted, false) |> assign(:form, to_form(Activities.change_activity(%Activity{})))} end @@ -21,9 +21,9 @@ defmodule WhoNeedHelpWeb.ActivityLive.New do @impl true def handle_event("validate", %{"activity" => params}, socket) do touched_keys = - MapSet.union( - socket.assigns.structured_touched_keys, - FormParams.touched_structured_keys(params) + Enum.uniq( + socket.assigns.structured_touched_keys ++ + FormParams.touched_structured_keys(params) ) params = FormParams.drop_unused_structured_fields(params) diff --git a/lib/who_need_help_web/live/request_live/new.ex b/lib/who_need_help_web/live/request_live/new.ex index 4f6de61..1de5e74 100644 --- a/lib/who_need_help_web/live/request_live/new.ex +++ b/lib/who_need_help_web/live/request_live/new.ex @@ -27,7 +27,7 @@ defmodule WhoNeedHelpWeb.RequestLive.New do |> assign(:categories, Catalog.list_categories()) |> assign(:selected_category, nil) |> assign(:structured_fields, []) - |> assign(:structured_touched_keys, MapSet.new()) + |> assign(:structured_touched_keys, []) |> assign(:structured_submit_attempted, false) |> assign(:submission_errors, []) |> assign(:form, to_form(changeset))} @@ -36,9 +36,9 @@ defmodule WhoNeedHelpWeb.RequestLive.New do @impl true def handle_event("validate", %{"help_request" => params}, socket) do touched_keys = - MapSet.union( - socket.assigns.structured_touched_keys, - FormParams.touched_structured_keys(params) + Enum.uniq( + socket.assigns.structured_touched_keys ++ + FormParams.touched_structured_keys(params) ) params = FormParams.drop_unused_structured_fields(params)