Disabling a Submit button "after" click stops submission #1625
Replies: 7 comments 5 replies
-
I am experiencing the exact same issue. Did you find a solution? |
Beta Was this translation helpful? Give feedback.
-
Not perfect, but you can get around with
|
Beta Was this translation helpful? Give feedback.
-
What about binding loading change to submit of form so it even waits for valid client validation?
|
Beta Was this translation helpful? Give feedback.
-
As @svenadlung suggested here is my solution to disable button with loading in front of text with some bootstrap. <div x-data="{loading: false}" x-on:submit="loading = true">
SOME FORM DATA etc.
<button x-bind:disabled="loading" class="btn btn-primary ms-auto" type="submit">
<span x-bind:class="{ 'spinner-border spinner-border-sm me-2': loading }" role="status"></span>
Submit
</button>
</div> Now I am curious how to change for example text <div x-data="{loading: false}" x-on:submit="loading = true">
SOME FORM DATA etc.
<button x-bind:disabled="loading" class="btn btn-primary ms-auto" type="submit">
<span x-bind:class="{ 'spinner-border spinner-border-sm me-2': loading }" role="status"></span>
<span x-bind:hidden="loading">Submit></span>
<span x-show="loading">Loading...</span>
</button>
</div> Is there somebody with better solution ? |
Beta Was this translation helpful? Give feedback.
-
here is my full code to disable button after clicked submit on form: <form x-data="{ buttonDisabled: false }" x-on:submit="buttonDisabled = true">
<button :disabled="buttonDisabled" x-text="buttonDisabled ? 'please wait...' : 'save'"></button>
</form> thanks @svenadlung |
Beta Was this translation helpful? Give feedback.
-
My approach is a small delay on disable to allow the click to propagate before setting disabled. I wanted a self contained button for both form and non-form uses, so attaching to the form was not an option.
|
Beta Was this translation helpful? Give feedback.
-
The simple version is just that you should have the form submit handler do whatever disabled the button instead of the button click itself. |
Beta Was this translation helpful? Give feedback.
-
This may need a better title and it's joined with livewire. This beat me to death today as I had to upgrade an app to use some new alpine 3 components and therefore upgraded the app to alpine v3 with the latest livewire.
A series of modals would not submit, took me a while to track down the issue, but it was this button! I have an attribute called long-running when a series of items need to be done that loads a spinner on the button for some feedback.
I left a console log in there to verify. The idea is simply show the spinner, and submit the form.
Beta Was this translation helpful? Give feedback.
All reactions