Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rutem's avatar
Level 1

Issue with simultaneous loading states display in Livewire button

Problem Description

I'm experiencing an issue with loading states display in a Livewire form button. The button is showing both states ("Send" and "Sending...") simultaneously instead of toggling between them correctly.

Current Code

<button type="submit" wire:loading.attr="disabled" class="w-full px-4 py-2 rounded-lg bg-indigo-700 text-white hover:bg-indigo-800 transition duration-150 ease-in-out disabled:opacity-50 disabled:cursor-not-allowed">
    <div class="flex items-center justify-center">
        <span wire:loading.remove wire:target="submit">
            Send
        </span>
        <span wire:loading wire:target="submit" class="flex items-center">
            <svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
                <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
            </svg>
            Sending...
        </span>
    </div>
</button>

How can I fix this simultaneous states display issue in the button? Is there a better way to handle loading states in Livewire?

Thank you in advance for your help!

0 likes
4 replies
tykus's avatar

Where is the submit action (not button type) that you are targetting? IMHO, you don't need the wire:target directive in this case; but maybe if there is a bigger context that we are not seeing???

rutem's avatar
Level 1

@tykus thanks for your reply.

this is the action on the livewire class :

public function submit()
    {
        $this->validate();

        try {
            Mail::raw("Nouveau message de contact:\n\nNom: {$this->name}\nEmail: {$this->email}\nTéléphone: {$this->phone}\n\nMessage:\n{$this->message}", function($message) {
                $message->to('')
                        ->subject('Nouveau message de contact');
            });

            $this->reset(['name', 'email', 'phone', 'message']);
            $this->dispatch('messageSent');
        } catch (\Exception $e) {
            $this->dispatch('messageError');
        }
    }

this is the complete form :

migsAV's avatar

@rutem because you are using wire:submit="submit" you can do the following with your button

<button 
+  type="submit"
-  type="button"
-   wire:click="submit"
   wire:loading.attr="disabled"
    ...rest of code
</button>

I would suggest changing your method name from submit to something else as well

tykus's avatar

@rutem if are using wire:submit on the form, then why have you changed the button to a button type, and added wire:click???

Please or to participate in this conversation.