sezaru
I have a LiveView with a form that has 2 buttons, a skip button and a submitbutton.
Both buttons have a CSS that checks if the button has the phx-submit-loading and shows a loading svg.
The issue is that I only want to change the loading in the button that I clicked, so, if I click in the skip button, I want to show the loading SVG in that button until the server replies. Same thing for the submit button.
But right now, it seems that LiveView will add the phx-submit-loading to all buttons instead of the one I clicked, and it doesn’t add any other class to the button I clicked. meaning that I don’t have a way to differentiate between them, and the loading svg ends up showing in both buttons which seems confusing for the user.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sodapopcan
I think you’re going to have to use a client side hook or get fancy with JS commands here.
The simplest non-hook approach I can come up with is:
Then add
phx-click={click()}to the appropriate buttons and target in CSS with:This will leave the
clickedclass on the button even after loading. Not super clean but also not a big deal if you target properly in CSS (it’s more of a “last clicked” class).You could also use a client-side hook and put it somewhere where it will apply to all buttons if that is what you’re after.
sezaru
Yeah, that is a good workaround, thanks for the tip I will use it in my project
It still sucks. I mean, AFAIK, LiveView knows exactly the button that was clicked, it could, for example, add
phx-submit-loadingto all buttons inside the form, but also addphx-click-loadingto the button that was clicked.It does already add the
phx-click-loadingclass to a button that is outside a form.sodapopcan
Gah, I gotta reread the docs, I wasn’t aware of
phx-click-loading. I guess you could just put some sort of no-op click on the buttons you want this to apply to. You could always request it get added (or something similar to it). I think it’s far more common to have a global loader in conjunction withphx-disable-withso my guess is that it just hasn’t come up yet.sezaru
I just opened a issue to see if they can add that, let’s see what the devs say
sodapopcan
Unless we’re unaware of it and you already can, it would actually be nice to be able to add a temporary class with some variant of
phx-disable-with. Though havingphx-click-loadingis probably enough.sezaru
Oh, for sure, that would be even better, I would even go further and add options to customize all the
phx-*classes in some way.sezaru
Now that you mentioned
phx-disable-with, that confirmed to me that LiveView does know what button was clicked since it will only apply that attribute change to the clicked button, not the otherssodapopcan
Oh, weird, I tested before I answered and thought it applied to all. Though I actually only looked for the
disabledattribute and nothing else but ya, of course that makes sense it only applies to the one, haha. Since that’s the case you can actually do what you want now with:sezaru
Oh, actually.. I talked too soon… I forgot to add the
phx-disable-withto my other buttonIt does apply to all of them
sodapopcan
Ah ok, I thought so but was tired of spinning up Phoenix apps to check