I have a project which contains a form. When the form has been successfully being received by the backend the button should be we swapped with a different button that confirms to the user that his request went trough.
But when I try to do this using Vue and transitions I can get the buttons to swap but the fading in and out doesn't work. The buttons just instantly swap.
This is the transition with the buttons inside the template:
<transition name="fade" mode="out-in">
<button
v-if="!valid"
class="my-3 px-4 py-3 rounded-md shadow-sm text-base font-medium text-white-primary bg-red-primary hover:bg-red-secondary"
@click="checkForm"
>
Request Beta Access
</button>
<button
v-if="valid"
class="my-3 px-4 py-3 rounded-md shadow-sm text-base font-medium text-white-primary bg-green-300 hover:bg-red-secondary"
@click="checkForm"
>
Request Sended
</button>
</transition>
This is the function where my local variable valid is being changed. I am using a timeout at this point to simulate the sending of the form to the backend. The first setTimeout simulates a small delay when you send the form to the backend. The second timeout is for displaying the success button for 2 seconds by changing the local valid variable:
async sendBetaRequest () {
setTimeout(() => {
this.clearForm()
this.valid = true
setTimeout(() => {
this.valid = false
}, 2000)
}, 1000)
},