Finally, we need to update the event handling clauses:
def handle_event("change", %{"text" => value}, socket) do
socket = assign(socket, :text_value, value)
{:noreply, socket}
end
def handle_event("add", %{"text" => value}, socket) do
SalesModule.Data.create_new(value)
socket = assign(socket, :text_value, nil)
{:noreply, socket}
end
Basically the idea here is that we’re setting up the HTML to be derived from the assign, so that when on submit we set the assign to nil, the value goes away. This does require (or at least, is works best when) we also track all of the form changes along the way.