silverdr
JS.show in handle_event instead of phx-click with JS.show
I have an element defined like
<img class="sdicon" phx-click={JS.show(to: "#click-target", transition: "fade-in-scale")} src={~p"/images/icons/myicon.png"}>
That works fine but I’d like to define it like:
<img class="sdicon" phx-click="icon-clicked" phx-value-target="#click-target" src={~p"/images/icons/myicon.png"}>
and have an event handler
def handle_event("icon-clicked", %{"target" => target} = unsigned_params, socket) do
# here some important stuff that needs to be done upfrong
# then an equivalent of JS.show(to: target, transition: "fade-in-scale")
{:noreply, socket}
end
that does some additional “important stuff” before the JS.show
Any suggestions how to do this “properly”? I know I can push custom event combined with window listener unless there are better options. But even then, how do I do the JS.show equivalent in the listener?
Most Liked
rhcarvalho
Hi!
Do you really want to wait until the server event is handled before changing the page?
If so, you have a few options:
- update an assign and let the LiveView update the page HTML
- send an event back to the client, which you can handle within a client hook
- dispatch an event stored in an attribute
- maybe others I don’t think of now
But maybe you’d be better off doing an optimistic UI change, see José Valim explain in https://youtu.be/fCdi7SEPrTs?si=iyxZM8FdE7clKYKI.
Also at Syncing changes and optimistic UIs in the official docs.
1
Popular in Questions
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir?
...
New
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Hi,
I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lists...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Hi!
Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Other popular topics
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hello guys,
I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine)
This is a plugin that adds support for Elixir to JetBrains IntelliJ...
New
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
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









