Current section

48 Versions

Jump to

Compare versions

4 files changed
+31 additions
-5 deletions
  @@ -1,5 +1,10 @@
1 1 # Changelog
2 2
3 + ## 0.2.4
4 +
5 + - Fixes a bug where variables in error messages where not interpolated.
6 + - Update to `phoenix_html` `3.3.x`
7 +
3 8 ## 0.2.3
4 9
5 10 - Clarified `layout` attributes to change the rendered order of slots.
  @@ -32,7 +32,7 @@
32 32 {<<"name">>,<<"phoenix_html">>},
33 33 {<<"optional">>,false},
34 34 {<<"repository">>,<<"hexpm">>},
35 - {<<"requirement">>,<<"~> 3.2.0">>}],
35 + {<<"requirement">>,<<"~> 3.3">>}],
36 36 [{<<"app">>,<<"phoenix_live_view">>},
37 37 {<<"name">>,<<"phoenix_live_view">>},
38 38 {<<"optional">>,false},
  @@ -43,4 +43,4 @@
43 43 {<<"optional">>,false},
44 44 {<<"repository">>,<<"hexpm">>},
45 45 {<<"requirement">>,<<"~> 1.4">>}]]}.
46 - {<<"version">>,<<"0.2.3">>}.
46 + {<<"version">>,<<"0.2.4">>}.
  @@ -170,11 +170,26 @@ defmodule PrimerLive.Helpers.FormHelpers do
170 170 ...> valid?: true
171 171 ...> }, :work_experience)
172 172 ["invalid value"]
173 +
174 + iex> PrimerLive.Helpers.FormHelpers.get_field_errors(
175 + ...> %{
176 + ...> action: :update,
177 + ...> changes: %{},
178 + ...> errors: [
179 + ...> first_name: {"should be at most %{count} character(s)",
180 + ...> [count: 255, validation: :length, kind: :max, type: :string]}
181 + ...> ],
182 + ...> data: nil,
183 + ...> valid?: true
184 + ...> }, :first_name)
185 + ["should be at most 255 character(s)"]
173 186 """
174 187 def get_field_errors(changeset, field) do
175 188 changeset.errors
176 189 |> Enum.filter(fn {error_field, _content} -> error_field == field end)
177 - |> Enum.map(fn {_error_field, {content, _details}} -> content end)
190 + |> Enum.map(fn {_error_field, {content, details}} ->
191 + interpolate_error_detials(content, details)
192 + end)
178 193 end
179 194
180 195 @doc """
  @@ -197,4 +212,10 @@ defmodule PrimerLive.Helpers.FormHelpers do
197 212
198 213 if is_nil(input_type), do: :text_input, else: input_type
199 214 end
215 +
216 + defp interpolate_error_detials(content, details) do
217 + Enum.reduce(details, content, fn {key, value}, content ->
218 + String.replace(content, "%{#{key}}", "#{inspect(value)}")
219 + end)
220 + end
200 221 end
  @@ -4,7 +4,7 @@ defmodule PrimerLive.MixProject do
4 4 def project do
5 5 [
6 6 app: :primer_live,
7 - version: "0.2.3",
7 + version: "0.2.4",
8 8 homepage_url: "https://github.com/ArthurClemens/primer_live",
9 9 description: description(),
10 10 package: package(),
  @@ -33,7 +33,7 @@ defmodule PrimerLive.MixProject do
33 33 {:ecto_sql, "~> 3.9"},
34 34 {:esbuild, "~> 0.7", only: :dev},
35 35 {:ex_doc, "~> 0.29", only: :dev},
36 - {:phoenix_html, "~> 3.2.0"},
36 + {:phoenix_html, "~> 3.3"},
37 37 {:phoenix_live_view, ">= 0.18.3"},
38 38 {:jason, "~> 1.4"}
39 39 ]