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

add options attribute to inputs_for/1 #2981

Merged
merged 1 commit into from
Jan 3, 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
9 changes: 9 additions & 0 deletions lib/phoenix_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,14 @@ defmodule Phoenix.Component do
"""
)

attr.(:options, :list,
default: [],
doc: """
Any additional options for the `Phoenix.HTML.FormData` protocol
implementation.
"""
)

slot.(:inner_block, required: true, doc: "The content rendered for each nested form.")

@persistent_id "_persistent_id"
Expand All @@ -2415,6 +2423,7 @@ defmodule Phoenix.Component do
parent_form.options
|> Keyword.take([:multipart])
|> Keyword.merge(options)
|> Keyword.merge(assigns.options)

forms = parent_form.impl.to_form(parent_form.source, parent_form, field_name, options)
seen_ids = for f <- forms, vid = f.params[@persistent_id], into: %{}, do: {vid, true}
Expand Down
20 changes: 20 additions & 0 deletions test/phoenix_component/components_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,26 @@ defmodule Phoenix.LiveView.ComponentsTest do
</form>
"""
end

test "with FormData implementation options" do
assigns = %{}

template = ~H"""
<.form :let={f} as={:myform}>
<.inputs_for
:let={finner}
field={f[:inner]}}
options={[foo: "bar"]}
>
<p><%= finner.options[:foo] %></p>
</.inputs_for>
</.form>
"""

html = t2h(template)
assert [p] = Floki.find(html, "p")
assert Floki.text(p) =~ "bar"
end
end

describe "live_file_input/1" do
Expand Down
Loading