Skip to content

Commit 8274c61

Browse files
committed
estado de cargando (Loading State)
1 parent 3d1157f commit 8274c61

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

script.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
const formulario = document.getElementById('contact-form');
2+
const sendButton = document.getElementById('send_button');
23

34
formulario.addEventListener('submit', async (evento) => {
45
evento.preventDefault();
6+
const originalButtonContent = sendButton.innerHTML;
7+
sendButton.disabled = true;
8+
sendButton.innerHTML = `
9+
<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span>
10+
Enviando...
11+
`;
512
const datos = new FormData(formulario);
613
const datosJson = Object.fromEntries(datos.entries());
714

@@ -26,5 +33,8 @@ formulario.addEventListener('submit', async (evento) => {
2633
} catch (error) {
2734
console.error('Error:', error);
2835
alert('No se pudo conectar con el servidor.');
36+
} finally {
37+
sendButton.disabled = false;
38+
sendButton.innerHTML = originalButtonContent;
2939
}
3040
});

0 commit comments

Comments
 (0)