I posted this question before, but I am feeling like that approach was a little bulky.
To recap, I am trying to set up behavior like the following diagram:
I have a LiveView set up that renders the form for a car (it’s not really a car. something much less interesting) but the form works correctly on the initial render. If I click the edit car link, the from pops up in the modal correctly.
I am trying to pass the current car_id to the LiveView, but I think I am misunderstanding how this works.
The liveview is rendered in the page using:
<%= live_render @conn, UrmedWebappWeb.FormModalComponent, conn: @conn %>
I initially tried to start the chain of events by using Hooks, and doing something like:
<a id="ds-<%= ds.id %>" ref="#" data-bs-toggle="modal" data-bs-target="#exampleModal"
phx-click="update_diagnosis_symptom_form"
phx-value-ds-id="<%= ds.id %>"
phx-hook="UpdateDiagnosisSymptomForm">
Edit
</a>
But I am now wondering if this approach will work at all, as I have something totally simple in my hook, like:
let Hooks ={}
Hooks.UpdateDiagnosisSymptomForm = {
mounted() {
console.log("mounted");
}
}
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {params: {_csrf_token: csrfToken, hooks: Hooks}})
when I click the link, nothing happens. the modal displays, but I get nothing in my console log. I am wondering if these bindings work only if I use them from inside a LiveView.
It seems like my problem is that I need to send a message from some random place on the dom (outside the LiveView) to the LiveView.
Am I completely off track here?