【发布时间】:2020-11-20 05:06:14
【问题描述】:
我在 Phoenix LiveView 中有一个带有 phx-submit 绑定的表单。可以通过单击“发送”按钮或在文本字段中按回车键来提交表单。
我的问题是,如果我通过按 enter 键提交表单,输入字段 IS NOT 被清除,但是如果我通过单击按钮提交,输入字段 IS 清除。
我希望在这两种情况下都清除输入字段。
下面是我的表格:
<%= f = form_for :chat_form, "#", phx_submit: :send, phx_target: @myself %>
<%= text_input f, :msg, autocomplete: "off" %>
<%= submit "Send" %>
</form>
还有我的handle_event 实现:
def handle_event("send", %{"chat_form" => %{"msg" => msg}}, socket) do
name = socket.assigns.name
Endpoint.broadcast("chat", "new_msg", %{sender: name, text: msg})
{:noreply, socket}
end
【问题讨论】:
标签: elixir phoenix-framework phoenix phoenix-live-view