Hello everyone
I am starting to get back into Elixir and found myself with an issue where I have an phx-click that is getting triggered on page mount. I do not recall this being an issue before, but cannot seem to find any resources about it. There was a post here which seemed similar but the conclusion there did not really leave me with anything to take away.
Here is my controller:
defmodule MyAppWeb.ApplicationController do
use MyAppWeb, :controller
alias MyApp.Repo
alias MyApp.Site.Application
def home(conn, %{"application_slug" => application_slug} = params) do
app = Repo.get_by(Application, application_slug: application_slug)
conn
|> put_flash(:info, "Hello")
|> assign(:layout, false)
|> assign(:application, app)
|> render(:home)
# render(conn, :home, layout: false, supplier_list: suppliers)
end
def register_for_doc_review(application_id) do
IO.puts("Registering #{application_id} for doc review")
end
end
and then the page is here:
<.flash_group flash={@flash} />
<div class="px-4 py-10 sm:px-6 sm:py-28 lg:px-8 xl:px-28 xl:py-32">
<.icon name="hero-beaker" class="h-12 w-12 bg-gradient-to-r from-blue-600 via-green-500 to-indigo-400" />
<div class="text-brand mt-10 flex items-center text-sm font-semibold leading-6">
</div>
<div class="text-center w-2/5 mx-auto border-solid border-2 border-sky-500">
<p class="text-[2rem] mt-4 font-semibold leading-10 tracking-tighter text-zinc-200">
<.icon name="hero-beaker" class="mt-2 h-14 w-14 bg-gradient-to-r from-blue-600 via-green-500 to-indigo-400" />
Application
</p>
<p>Show the Application</p>
<p>Name: <%= @application.first_name %></p>
<p>Name: <%= @application.last_name %></p>
<button onclick={MyAppWeb.ApplicationController.register_for_doc_review(@application.application_id)}>🔍</button>
</div>
</div>
Then whenever I go to the page, without clicking or anything in the console I get
Registering 1 for doc review
[info] Sent 200 in 189ms
I guess I am just wondering if this is expected. I would have to suspect I am just implementing something incorrectly as this would have to be something mentioned elsewhere, no?
Also worth mentioning when I do click on it nothing happens.
Thanks all