Valeriy
Form phx-change don't work after csv download
Hi guys!
I try CSV Export with Phoenix and LiveView with this guide CSV Export with Phoenix and LiveView - Tutorials and screencasts for Elixir, Phoenix and LiveView (fullstackphoenix.com).
I use filters for data displayed as a table on my heex:
<form phx-change=“filter” class=“pt-4 pb-4 text-sm”>
<span class=“inline-flex”>
<span>
<label>node:</label>
<%= Phoenix.HTML.Form.number_input(:options, :node,
value: @options.node,
“phx-debounce”: “300”,
class: “text-sm border border-slate-300 text-slate-600 w-20 ml-2 mr-4”
) %>
</span>
<span>
<label>date:
<%= Phoenix.HTML.Form.date_input(:options, :date,
value: @options.date,
class: “text-sm border border-slate-300 text-slate-600 ml-2 mr-4”
) %>
</span>
</span>
</form>
and link to export on the same heex:
<.link
href={~p"/export?#{%{message: “journals”, node: @options.node, date: @options.date, sort_by: @options.sort_by, sort_order: @options.sort_order}}“}
method=“post”
class=”-ml-px inline-flex items-center px-3 h-10 border border-slate-300 bg-white text-base font-medium text-slate-600 no-underline hover:bg-slate-300 rounded-md"
>
Export
</.link>
In export controller:
def create(conn, %{“message” => “journals”, “node” => node, “date” => date, “sort_by” => sort_by, “sort_order” => sort_order}) do
…
csv_data = …conn
|> put_resp_content_type(“text/csv”)
|> put_resp_header(“content-disposition”, “attachment; filename="journals.csv"”)
|> put_root_layout(false)
|> send_resp(200, csv_data)
end
CSV export works fine, but i have some quiestion: the filter (form) stops responding to changes after loading csv-file, but all other links work (pagination and sorting).
It seems that “phx-change” don’t send any messages to my live_view.
I also read this topics, but could not find an answer to my question:
- Changing form contents on
phx-change- Phoenix Forum / Questions / Help - Elixir Programming Language Forum (forum.elixirforum.com) - Form not firing phx-change in LiveView - Phoenix Forum / Questions / Help - Elixir Programming Language Forum (forum.elixirforum.com)
Thank you.
First Post!
codeanpeace
Off the top of my head, I suspect what’s going on here is that the LiveView socket disconnects on export since clicking a default generated <.link href=...> results in traditional browser navigation. You can check if this is the case by using the phx-disconnected binding to show/do something.
If that is the case, you could try specifying the anchor tag’s download attribute and/or target attribute as new tab and see if that makes a difference.
Updated to add:
https://github.com/phoenixframework/phoenix_live_view/issues/2552
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









