Hello thank you for your response. Here are the relevant parts of the code.
Here is the live view
defmodule MyappWeb.ExampleLive do
use Phoenix.LiveView
def mount(_params, session, socket) do
# this code is triggered and connection is ok
IO.inspect(connected?(socket), label: "CONNECTION STATUS")
{
:ok,
assign(
socket,
%{
"key" => value
}
)
}
end
def handle_event("validate", value, socket) do
# this code is not triggered
IO.inspect(connected?(socket), label: "HANDLE_PHX_CHANGE")
newval = value["response"]["response"]
{:noreply, assign(socket, response: newval )}
end
...
next here is the app.js
import css from "../css/app.css";
import "phoenix_html";
// IE11 Support for LiveView
import "mdn-polyfills/CustomEvent";
import "mdn-polyfills/String.prototype.startsWith";
import "mdn-polyfills/Array.from";
import "mdn-polyfills/NodeList.prototype.forEach";
import "mdn-polyfills/Element.prototype.closest";
import "mdn-polyfills/Element.prototype.matches";
import "child-replace-with-polyfill";
import "url-search-params-polyfill";
import "formdata-polyfill";
import "classlist-polyfill";
import {Socket} from "phoenix";
import {LiveSocket} from "phoenix_live_view";
import NProgress from "nprogress";
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken}});
window.addEventListener("phx:page-loading-start", info => NProgress.start())
window.addEventListener("phx:page-loading-stop", info => NProgress.done())
liveSocket.connect();
// expose liveSocket on window for web console debug logs and latency simulation:
liveSocket.enableDebug()
liveSocket.enableLatencySim(1000)
window.liveSocket = liveSocket
Next here are the general configs
defmodule MyappWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :myapp
@session_options [
store: :cookie,
key: "_myapp_key",
signing_salt: "BAjfAPWj"
]
socket "/socket", MyappWeb.UserSocket,
websocket: true,
longpoll: false
socket "/live", Phoenix.LiveView.Socket,
websocket: [connect_info: [session: @session_options]]
it’s not clear why a new live_view function is needed, previously it was merged with view
the template live.html does not exist there is only the regular app layout template. Maybe this is the reason ?
defmodule MyappWeb do
...
def live_view do
quote do
use Phoenix.LiveView,
layout: {MyappWeb.LayoutView, "live.html"}
unquote(view_helpers())
end
end
def live_component do
quote do
use Phoenix.LiveComponent
unquote(view_helpers())
end
end
def router do
quote do
use Phoenix.Router
import Plug.Conn
import Phoenix.LiveView.Router
import Phoenix.Controller
end
end
def channel do
quote do
use Phoenix.Channel
import MyappWeb.Gettext
end
end
defp view_helpers do
quote do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
# Import LiveView helpers (live_render, live_component, live_patch, etc)
import Phoenix.LiveView.Helpers
# Import basic rendering functionality (render, render_layout, etc)
import Phoenix.View
import MyappWeb.ErrorHelpers
import MyappWeb.Gettext
alias MyappWeb.Router.Helpers, as: Routes
end
end
@doc """
When used, dispatch to the appropriate controller/view/etc.
"""
defmacro __using__(which) when is_atom(which) do
apply(__MODULE__, which, [])
end
end
Finally here is the template it is rendered within the general app template,
<%= form_for @changeset, @action,[phx_change: :validate, class: "overflow-visible", id: "responseform"], fn f -> %>
<%= live_render(@conn, MyappWeb.ExampleLive, session: %{"response" => @response.response,}) %>
<%= render(MyappWeb.SharedView, "checkbox.html") %>
<%= submit %>
<% end %>