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

render_hook/3 fails without explicit phx-target #3315

Open
LostKobrakai opened this issue Jun 21, 2024 · 1 comment
Open

render_hook/3 fails without explicit phx-target #3315

LostKobrakai opened this issue Jun 21, 2024 · 1 comment

Comments

@LostKobrakai
Copy link
Contributor

Environment

  • Elixir version (elixir -v): 1.17.0
  • Phoenix version (mix deps): 1.7.0
  • Phoenix LiveView version (mix deps): 1.0.0-rc.4
  • Operating system: Mac OS
  • Browsers you attempted to reproduce this bug on (the more the merrier):
  • Does the problem persist after removing "assets/node_modules" and trying again? Yes/no:

Actual behavior

Using render_hook(element(view, "#hook-el-id"), "event", map) requires #hook-el-id to have a phx-target attribute for the render_hook/3 to work.

Expected behavior

The phx-target attribute seems to not be required outside of tests and it would seems to hold the same value as data-phx-component anyways. My expectation would be that phx-target shouldn't be required for render_hook/3 as well.

@foucist
Copy link

foucist commented Jun 28, 2024

The documentation says:

If you are pushing events from a hook to a component, then you must pass an element, created with element/3, as first argument and it must point to a single element on the page with a phx-target attribute in it:

The requirement that it must be a single element seems inconvenient, especially when my phx-hook (and therefore phx-target) is on a div containing other elements.

I had a test for a sortable list <div phx-hook="Sortable" working just fine with render_hook(view, "update-sorting", %{"ids" => sort}), but the moment I tried to use it in the Table component <tbody phx-hook="Sortable" phx-target="sortable-table, render_hook no longer returns the updated result, or complains about the selector not returning a single element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants