yassine ben
yassine ben

Reputation: 23

Send input values from root template phoenix

I have this form in my file root.html.leex, and I want to handle this event but I don't know where I must handle it!

<form phx-submit="topic-search" >
  <input type="text"
         name="req"
         placeholder="Search Topics, Posts,..."
         class="form-control"
         style="margin-top: 20px"/>
  <button type="submit"> </button>
</form>

Upvotes: 0

Views: 582

Answers (2)

Aqdas Malik
Aqdas Malik

Reputation: 179

There is not a proper way of doing this mentioned anywhere, and what I am about to suggest is just a workaround to achieve what you want.

Make a simple module in you application

defmodule RootFormHelper do

  def handle_event("topic-search", params, socket) do
    // your code here
  end

end

After you create this module simply use this like, use RootFormHelper, :handle_event in all your live views which have root.html.leex set as there layout.

Your form will start working. 🥂

Upvotes: 1

pablodavila
pablodavila

Reputation: 69

You need a handle_event function in your LiveView code. You can refer to this for references regarding forms in LV.

Upvotes: 0

Related Questions