good Afternoon, I have a live_view component with a input hidden field “attached” to a phx-hook
1–in the template:
<form id="login_form" phx-submit="check_login_credentials">
<input type="hidden" id="login_token" phx-hook="input_login_token"/>
.
.
.
</form>
2–in the server:
there’s a function handle_event/3
that processes the username and password and send it to an external Auth API in Django using djoser REST API. and receives a token.
def handle_event("check_login_credentials", params, socket) do
login_tkn="823703847509432870598743205987" #test dummy data
if login_tkn do
{:noreply, push_event(socket, "saveLoginToken", %{login_token : login_tkn}
.
.
.
end
end
3—in the hooks file app.js theres a hook declared who manipulates the data sent from the server
let hooks = {}
hooks.saveLogintoken ={
mounted() {
localStorage.clear()
this.handleEvent("saveLoginToken", ({login_tkn}) => localStorage.setItem("login_token", login_tkn)
},
};
When I put a console.log(something) in after the mounted()
section it prints in the console, but any code put in this.handleEvent()
section is not executed, If i take the other aproach and use
this.el.addEventListener("input", e => {....}
it works but not handleEvent
could anybody explain why is not working, thanks in advanced.