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

Form bindings & JS commands #3607

Closed
IdoLeshkowitz opened this issue Dec 29, 2024 · 1 comment · Fixed by #3608
Closed

Form bindings & JS commands #3607

IdoLeshkowitz opened this issue Dec 29, 2024 · 1 comment · Fixed by #3608
Assignees
Labels

Comments

@IdoLeshkowitz
Copy link

IdoLeshkowitz commented Dec 29, 2024

Environment

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

Actual behavior

Found an inconsistent behavior while using forms bindings & JS commands, binding a JS command to phx-change doesnt work well on recovery cause the JS command doesnt get evaluated properly and pushes a non-parsed event, I added a minimal example, try disconnecting and reconnecting to see the error. does using JS commands with form bindings is something that I should not be doing? or is it an issue?

Mix.install([
  {:phoenix_playground, "~> 0.1.6"}
])

defmodule DemoLive do
  use Phoenix.LiveView
  alias Phoenix.LiveView.JS

  def mount(_params, _session, socket) do
    {:ok, socket}
  end

  def handle_event("validate", _, socket) do
    {:noreply, socket}
  end

  def render(assigns) do
    ~H"""
    <form phx-change="validate" id="form1">
      <input name="name" id="name1"/>
    </form>
    <form phx-change={JS.push("validate")} id="form2">
      <input name="name" id="name2"/>
    </form>
    """
  end

end
PhoenixPlayground.start(live: DemoLive)

Expected behavior

JS.push will always result with the same event reaching the server, no matter if the form is recovering or just changed.

@IdoLeshkowitz
Copy link
Author

💥

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

Successfully merging a pull request may close this issue.

2 participants