Context:
I am trying to setup a simple liveview form.
Help:
When I visit the form /client/new
and submit an entry, phx_submit
event doesn’t get triggered. It instead makes a post request to /client/new
which doesn’t exist.
lib/contact_us_web/live/client_live/index.ex
defmodule ContactUsWeb.ClientLive.Index do
use Phoenix.LiveView
alias ContactUsWeb.Router.Helpers, as: Routes
alias ContactUsWeb.ClientView
alias ContactUs.Accounts
alias ContactUs.Accounts.Client
def mount(_session, socket) do
changeset = Accounts.change_client(%Client{})
{:ok, assign(socket, :changeset, changeset)}
end
def render(assigns) do
Phoenix.View.render(ClientView, "form.html", assigns)
end
def handle_event("save", args, socket) do
IO.inspect(args, label: "VALDIATE DATA")
{:noreply, socket}
end
end
lib/contact_us_web/templates/client/form.html.leex
<%= form_for @changeset, "#", [phx_submit: "save"], fn f -> %>
<%= label f, :first_name %>
<%= text_input f, :first_name %>
<%= error_tag f, :first_name %>
<%= label f, :last_name %>
<%= text_input f, :last_name %>
<%= error_tag f, :last_name %>
<%= label f, :email_address %>
<%= text_input f, :email_address %>
<%= error_tag f, :email_address %>
<%= label f, :phone_number %>
<%= text_input f, :phone_number %>
<%= error_tag f, :phone_number %>
<%= label f, :company %>
<%= text_input f, :company %>
<%= error_tag f, :company %>
<%= label f, :service %>
<%= text_input f, :service %>
<%= error_tag f, :service %>
<div>
<%= submit "Save", phx_disable_with: "Saving..." %>
</div>
<% end %>
I made sure everything is setup properly. However, I’m unable to determine what the issue is.