Is there a way to keep loading state on the form while waiting for client to respond, like a server-side version of pushEvent?

I have a form where the user can select one of a few payment options. One of the options uses a third party that injects iframes into the page to collect credit card data from the user, and those fields need to be submitted via JS. To accomplish this, I use push_event when the form is submitted (along with some other server-side tasks), which works as expected. My issue is that using push_event turns off the form loading state, which makes the form look like nothing is happening.

I could use JS to put the phx-submit-loading class back on the button during the push_event but I wonder if there is a better solution? Is there a way to keep the loading state on the form while waiting for the client to respond, like a server-side version of pushEvent?

Why don’t you explicitly control loading states?

<%= if @loading do %>
  "Loading..."
<% end %>

Then, when you receive the response back from the client in the handle_event/3 callback, you set loading to false.

@impl true
def handle_event("client_event", unsigned_params, socket)  do
  {:noreply, assign(socket, loading: false)}
end

The other payment options are server-side only, I was hoping to keep the same look and feel for both server and client side. I will use a loading state if there is no way to wait for a response from the client.