Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you attach functionality to buttons in Embedded Elixir?

I'm rendering templates like so:

<%= for country <- @countries do %>
  <div>
    <div>A list of countries you have visited</div>
    <a href="/countries/<%= String.downcase(country) %>"><%= country %></a>
    <button> Click This </button>
  </div>
<% end %>

in js of course I can do <button onclick={myFunction}/> but how do I do this in template world in elixir?

like image 906
Red Baron Avatar asked Sep 08 '26 14:09

Red Baron


1 Answers

Phoenix provides a lot of binding events which you can utilise in the phoenix based apps.

For e.g. if you want to call a function on click of a button then use the phx-click to call the function in the elixir module.

You can read more about the bindings.

https://hexdocs.pm/phoenix_live_view/bindings.html

like image 94
Yatender Singh Avatar answered Sep 12 '26 08:09

Yatender Singh