Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To form vs form for #146

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion example/lib/live_phone_example_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ defmodule LivePhoneExampleWeb do
defp view_helpers do
quote do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
import Phoenix.HTML
import Phoenix.HTML.Form
use PhoenixHTMLHelpers

# Import LiveView helpers (live_render, live_component, live_patch, etc)
import Phoenix.LiveView.Helpers
Expand Down
4 changes: 3 additions & 1 deletion example/lib/live_phone_example_web/views/error_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ defmodule LivePhoneExampleWeb.ErrorHelpers do
Conveniences for translating and building error messages.
"""

use Phoenix.HTML
import Phoenix.HTML
import Phoenix.HTML.Form
use PhoenixHTMLHelpers

@doc """
Generates tag for inlined form input errors.
Expand Down
3 changes: 2 additions & 1 deletion lib/live_phone.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ defmodule LivePhone do
"""

use Phoenix.LiveComponent
use Phoenix.HTML
import Phoenix.HTML.Form
use PhoenixHTMLHelpers

alias Phoenix.LiveView.Socket
alias LivePhone.{Country, Util}
Expand Down
5 changes: 3 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ defmodule LivePhone.MixProject do
def project do
[
app: :live_phone,
version: "0.7.0",
elixir: "~> 1.12",
version: "0.7.1",
elixir: "~> 1.13",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can also keep this at 1.12 if needed

elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
description: description(),
Expand Down Expand Up @@ -58,6 +58,7 @@ defmodule LivePhone.MixProject do
[
{:phoenix_live_view, ">= 0.0.0"},
{:phoenix_html, ">= 0.0.0"},
{:phoenix_html_helpers, "~> 1.0"},
{:ex_phone_number, ">= 0.0.0"},
{:jason, ">= 0.0.0"},
{:iso, ">= 0.0.0"},
Expand Down
65 changes: 33 additions & 32 deletions mix.lock

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions test/live_phone_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule LivePhoneTest do
use ExUnit.Case
import Phoenix.{LiveViewTest, ConnTest}
alias Phoenix.HTML.FormData
doctest LivePhone

@endpoint LivePhoneTestApp.Endpoint
Expand Down Expand Up @@ -61,28 +62,32 @@ defmodule LivePhoneTest do
end

test "support setting form and field from changeset (new)" do
use Phoenix.HTML
use PhoenixHTMLHelpers

changeset = LivePhoneTestApp.User.changeset()

form = form_for(changeset, "/")
component = render_live_phone(id: "livephone", form: form, field: :phone)
component =
render_live_phone(id: "livephone", form: FormData.to_form(changeset, []), field: :phone)

assert component =~ "name=\"user[phone]\""
assert component =~ "value=\"\""
end

test "support setting form and field from changeset (edit)" do
use Phoenix.HTML
use PhoenixHTMLHelpers

changeset =
LivePhoneTestApp.User.changeset(
%LivePhoneTestApp.User{},
%{id: 1, phone: "+16502530000"}
)

form = form_for(changeset, "/")
component = render_live_phone(id: "livephone", form: form, field: :phone)
component =
render_live_phone(
id: "livephone",
form: FormData.to_form(changeset, []),
field: :phone
)

assert component =~ "name=\"user[phone]\""
assert component =~ "value=\"+16502530000\""
Expand Down
2 changes: 1 addition & 1 deletion test/support/test_endpoint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule LivePhoneTestApp do
end

defmodule Page do
use Phoenix.HTML
use PhoenixHTMLHelpers
use Phoenix.LiveView

@impl true
Expand Down
Loading