Skip to content

Commit 7702e9c

Browse files
Update LiveView to 1.1
1 parent cf6af0b commit 7702e9c

File tree

7 files changed

+49
-40
lines changed

7 files changed

+49
-40
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
elixir 1.14.5
1+
elixir 1.16.3
22
erlang 25.1.2
33
nodejs 16.13.0

lib/bitstyles_phoenix/component/error.ex

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
defmodule BitstylesPhoenix.Component.Error do
22
use BitstylesPhoenix.Component
3-
alias Phoenix.HTML.Form, as: PhxForm
43

54
@moduledoc """
65
Component for showing UI errors.
@@ -33,28 +32,28 @@ defmodule BitstylesPhoenix.Component.Error do
3332
""",
3433
"6.0.0": """
3534
\"""
36-
<span class="u-fg-warning" phx-feedback-for="user[name]">
35+
<span class="u-fg-warning">
3736
is too short
3837
</span>
3938
\"""
4039
""",
4140
"5.0.1": """
4241
\"""
43-
<span class="u-fg-warning" phx-feedback-for="user[name]">
42+
<span class="u-fg-warning">
4443
is too short
4544
</span>
4645
\"""
4746
""",
4847
"4.3.0": """
4948
\"""
50-
<span class="u-fg-warning" phx-feedback-for="user[name]">
49+
<span class="u-fg-warning">
5150
is too short
5251
</span>
5352
\"""
5453
""",
5554
"3.0.0": """
5655
\"""
57-
<span class="u-fg--warning" phx-feedback-for="user[name]">
56+
<span class="u-fg--warning">
5857
is too short
5958
</span>
6059
\"""
@@ -73,12 +72,12 @@ defmodule BitstylesPhoenix.Component.Error do
7372
\"""
7473
<ul class="u-padding-l3-left">
7574
<li>
76-
<span class="u-fg-warning" phx-feedback-for="user[email]">
75+
<span class="u-fg-warning">
7776
is invalid
7877
</span>
7978
</li>
8079
<li>
81-
<span class="u-fg-warning" phx-feedback-for="user[email]">
80+
<span class="u-fg-warning">
8281
must end with @bitcrowd.net
8382
</span>
8483
</li>
@@ -87,9 +86,10 @@ defmodule BitstylesPhoenix.Component.Error do
8786
"""
8887
)
8988

90-
def ui_errors(assigns) do
91-
assigns.form.errors
92-
|> Keyword.get_values(assigns.field)
89+
def ui_errors(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
90+
errors = if Phoenix.Component.used_input?(field), do: field.errors, else: []
91+
92+
errors
9393
|> case do
9494
[] ->
9595
~H""
@@ -100,7 +100,6 @@ defmodule BitstylesPhoenix.Component.Error do
100100
~H"""
101101
<.ui_error
102102
error={@error}
103-
phx-feedback-for={PhxForm.input_name(assigns.form, assigns.field)}
104103
class={assigns[:error_class]} />
105104
"""
106105

@@ -114,7 +113,6 @@ defmodule BitstylesPhoenix.Component.Error do
114113
<li>
115114
<.ui_error
116115
error={error}
117-
phx-feedback-for={PhxForm.input_name(assigns.form, assigns.field)}
118116
class={assigns[:error_class]} />
119117
</li>
120118
<% end %>
@@ -123,6 +121,10 @@ defmodule BitstylesPhoenix.Component.Error do
123121
end
124122
end
125123

124+
def ui_errors(%{field: field, form: form} = assigns) do
125+
assigns |> assign(:field, form[field]) |> ui_errors()
126+
end
127+
126128
@doc """
127129
Generates tag for custom errors.
128130
@@ -180,12 +182,12 @@ defmodule BitstylesPhoenix.Component.Error do
180182
"""
181183
iex> assigns = %{error: {"Foo error", []}}
182184
...> render ~H\"""
183-
...> <.ui_error error={@error} phx-feedback-for="foo" class="bar" />
185+
...> <.ui_error error={@error} class="bar" />
184186
...> \"""
185187
""",
186188
"""
187189
\"""
188-
<span class="u-fg-warning bar" phx-feedback-for="foo">
190+
<span class="u-fg-warning bar">
189191
Foo error
190192
</span>
191193
\"""

lib/bitstyles_phoenix/component/form.ex

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ defmodule BitstylesPhoenix.Component.Form do
124124
<label for="user_name">
125125
Name
126126
</label>
127-
<input id="user_name" name="user[name]" type="text" maxlength="255"/>
128-
<span class="u-fg-warning" phx-feedback-for="user[name]">
127+
<input id="user_name" name="user[name]" type="text" maxlength="255" value="funky"/>
128+
<span class="u-fg-warning">
129129
is too short
130130
</span>
131131
\"""
@@ -145,15 +145,15 @@ defmodule BitstylesPhoenix.Component.Form do
145145
<label for="user_email">
146146
Email
147147
</label>
148-
<input id="user_email" name="user[email]" type="text" maxlength="255"/>
148+
<input id="user_email" name="user[email]" type="text" maxlength="255" value="foo@bar"/>
149149
<ul class=\"u-padding-l3-left\">
150150
<li>
151-
<span class=\"u-fg-warning\" phx-feedback-for=\"user[email]\">
151+
<span class=\"u-fg-warning\">
152152
is invalid
153153
</span>
154154
</li>
155155
<li>
156-
<span class=\"u-fg-warning\" phx-feedback-for=\"user[email]\">
156+
<span class=\"u-fg-warning\">
157157
must end with @bitcrowd.net
158158
</span>
159159
</li>
@@ -516,8 +516,9 @@ defmodule BitstylesPhoenix.Component.Form do
516516
Name
517517
</label>
518518
<textarea id="user_name" name="user[name]">
519+
funky
519520
</textarea>
520-
<span class="u-fg-warning" phx-feedback-for="user[name]">
521+
<span class="u-fg-warning">
521522
is too short
522523
</span>
523524
\"""
@@ -740,7 +741,7 @@ defmodule BitstylesPhoenix.Component.Form do
740741
</label>
741742
Custom content
742743
<input type="text" whatever="foo"/>
743-
<span class="u-fg-warning" phx-feedback-for="user[name]">
744+
<span class="u-fg-warning">
744745
is too short
745746
</span>
746747
\"""

lib/bitstyles_phoenix/component/heading.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ defmodule BitstylesPhoenix.Component.Heading do
282282
~H"""
283283
<div class={@class} {@extra}>
284284
<div class={classnames("u-flex u-items-center")}>
285-
<.dynamic_tag name={@tag} class={classnames(["u-margin-0 u-margin-m-right u-break-text", assigns[:heading_class]])}>
285+
<.dynamic_tag tag_name={Atom.to_string(@tag)} class={classnames(["u-margin-0 u-margin-m-right u-break-text", assigns[:heading_class]])}>
286286
<%= render_slot(@inner_block) %>
287287
</.dynamic_tag>
288288
<%= assigns[:title_extra] && render_slot(@title_extra) %>

lib/bitstyles_phoenix/helper/test_fixtures.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ defmodule BitstylesPhoenix.Helper.TestFixtures do
1010
end
1111

1212
def form_with_errors do
13-
Phoenix.Component.to_form(%{},
13+
Phoenix.Component.to_form(
14+
%{
15+
"name" => "funky",
16+
"email" => "foo@bar",
17+
"_unused_password" => ""
18+
},
1419
as: :user,
1520
errors: [
1621
name: {"is too short", []},
22+
password: {"too short", []},
1723
email: {"is invalid", []},
1824
email: "must end with @bitcrowd.net"
1925
]

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ defmodule BitstylesPhoenix.MixProject do
5252
defp deps do
5353
[
5454
{:jason, "~> 1.0"},
55-
{:phoenix_live_view, "~> 0.18.12 or ~> 0.19.0 or ~> 0.20.0"},
56-
{:phoenix_html, "~> 3.3 or ~> 4.0"},
55+
{:phoenix_live_view, "~> 1.0"},
56+
{:phoenix_html, "~> 4.0"},
5757
{:floki, "~> 0.38", only: [:test, :dev]},
5858
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
5959
{:credo, ">= 0.0.0", only: :dev, runtime: false}

0 commit comments

Comments
 (0)