Skip to content
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
14 changes: 13 additions & 1 deletion assets/js/phoenix_live_view/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
MAX_CHILD_JOIN_ATTEMPTS,
PHX_LV_PID,
PHX_NO_USAGE_TRACKING,
PHX_PORTAL,
PHX_TELEPORTED_REF,
} from "./constants";

import {
Expand Down Expand Up @@ -641,6 +643,13 @@ export default class View {
// recovery events are done.
const template = document.createElement("template");
template.innerHTML = html;

// we special case <.portal> here and teleport it into our temporary DOM for recovery
// as we'd otherwise not find teleported forms
DOM.all(template.content, `[${PHX_PORTAL}]`).forEach((portalTemplate) => {
template.content.appendChild(portalTemplate.content);
});

// because we work with a template element, we must manually copy the attributes
// otherwise the owner / target helpers don't work properly
const rootEl = template.content.firstElementChild;
Expand Down Expand Up @@ -2109,7 +2118,10 @@ export default class View {

const phxChange = this.binding("change");

return DOM.all(this.el, `form[${phxChange}]`)
return DOM.all(
document,
`#${CSS.escape(this.id)} form[${phxChange}], [${PHX_TELEPORTED_REF}="${CSS.escape(this.id)}"] form[${phxChange}]`,
)
.filter((form) => form.id)
.filter((form) => form.elements.length > 0)
.filter(
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/support/form_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ for type <- [FormLive, FormLiveNested] do
@impl Phoenix.LiveView
def render(assigns) do
~H"""
<h1 :if={@params["portal"]}>Form</h1>

<.my_form :if={!@params["live-component"]} params={@params} />
<.live_component
:if={@params["live-component"]}
Expand All @@ -143,6 +145,14 @@ for type <- [FormLive, FormLiveNested] do
"""
end

def my_form(%{params: %{"portal" => _}} = assigns) do
~H"""
<.portal id="form-portal" target="body">
<.my_form params={Map.delete(@params, "portal")} />
</.portal>
"""
end

def my_form(assigns) do
~H"""
<form
Expand Down
Loading
Loading