Skip to content

Commit

Permalink
Respect to_form :as option in form field access (#2480)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko authored Feb 22, 2023
1 parent 5bfe422 commit c4234a5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/phoenix_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2094,15 +2094,13 @@ defmodule Phoenix.Component do
attr.(:for, :any, required: true, doc: "An existing form or the form source data.")

attr.(:action, :string,
default: nil,
doc: """
The action to submit the form on.
This attribute must be given if you intend to submit the form to a URL without LiveView.
"""
)

attr.(:as, :atom,
default: nil,
doc: """
The server side parameter in which all params for this form
will be collected. For example, setting `as: :user_params` means
Expand Down
19 changes: 19 additions & 0 deletions test/phoenix_component/components_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,25 @@ defmodule Phoenix.LiveView.ComponentsTest do
] = html
end

test "generates form with prebuilt form and :as" do
assigns = %{form: to_form(%{}, as: :data)}

template = ~H"""
<.form :let={f} for={@form}>
<input id={f[:foo].id} name={f[:foo].name} type="text" />
</.form>
"""

html = parse(template)

assert [
{"form", [],
[
{"input", [{"id", "data_foo"}, {"name", "data[foo]"}, {"type", "text"}], []}
]}
] = html
end

test "generates form with prebuilt form and options" do
assigns = %{form: to_form(%{})}

Expand Down

0 comments on commit c4234a5

Please sign in to comment.