I am very new to the Phoenix Framework. All I am trying to do is to get the input text from an html input, which is supposed to be a message in a chat. Then I want to add that text to the chat history below.
I don’t need changesets, databases and I think I don’t even need forms (?). All I want to do is get the input and concatenate it to an ever longer chat log.
My code so far:
defmodule ChatWeb.ChatLive do
use ChatWeb, :live_view
def mount(params, session, socket) do
{:ok, assign(socket, :text_value, "")}
end
def render(assigns) do
~H"""
<h1>Chat</h1>
<label>Your Text:<input id="msg" type="text" /></label>
<button phx-click="send-msg">Send</button>
<div id="chat">
Chat history: <%= @text_value %>
</div>
"""
end
def handle_event("send-msg", _, socket) do
msg = "what do I do here?"
{:noreply, assign(socket, :text_value, msg)}
end
end
Thanks so much in advance!