#Laravel LiveWire click methods being executed twice

1 messages · Page 1 of 1 (latest)

solemn thunder
#

I am pulling my hair out on this - i have. simple form that is inside of LiveWire component that when clicked, is executing the submit method 2 times in succession.

I've combed the code for anywhere that I might be calling a function more than once and am quite sure that i don't have a duplicate and that there must be something either in the submit lifecycle or something else I've missed to look into.

Any chance someone has pointer on where to look next to stop this, or how I might trace the flow inside of a livewire component?

-- HTML markup
<form method='dialog' wire:submit.prevent='save'>
... form elements ...
<button wire:click='save' >Save</button>

--- function definition in the livewire class

function save() {
dump("clicked!");
}

---- and the output when clicked
clicked!
clicked!
crisp quest
#

But your html literally has call to save() twice

#

What's the problem

#

Button is submitting the form but also triggering the method you put in it

solemn thunder
#

this is a dumb question then - should i be using @click or the method attribute?

crisp quest
#

Wdym

#

Either use wire:submit on your form OR wire click on the button

#

Not both

solemn thunder
#

smh. that fixed it. Thanks for this - still new to livewire and thought i had that correct

crisp quest
#

On that note -please remember about wire:keys in loops!