Skip to content

Commit a4a587f

Browse files
Disable Register button while submission is in-flight
Prevents double-submits by disabling the button, swapping its label to "Saving…", and switching the cursor to not-allowed until the request resolves. On error the button and its label are restored so the user can retry.
1 parent 5b47fb9 commit a4a587f

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

common-theme/layouts/partials/register-attendance.html

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h2 class="c-block__title e-heading__2" id="register">
6262
</datalist>
6363
</div>
6464
{{ end }}
65-
<button class="e-button">Register</button>
65+
<button type="submit" class="e-button">Register</button>
6666
</form>
6767
</section>
6868

@@ -71,19 +71,30 @@ <h2 class="c-block__title e-heading__2" id="register">
7171
const handleSubmit = (event) => {
7272
event.preventDefault();
7373
const registration = event.target;
74+
const submitButton = registration.querySelector("button[type=submit]");
75+
const originalLabel = submitButton.textContent;
76+
submitButton.disabled = true;
77+
submitButton.style.cursor = "not-allowed";
78+
submitButton.textContent = "Saving…";
79+
7480
const requestBody = {};
7581
const formData = new FormData(registration);
7682
for (const [key, value] of formData.entries()) {
7783
requestBody[key] = value;
7884
}
79-
85+
8086
fetch("https://portal-backend.codeyourfuture.io/functions/v1/submit-class-register-form", {
8187
method: "POST",
8288
headers: { "Content-Type": "application/json" },
8389
body: JSON.stringify({"payload": {"data": requestBody}}),
8490
})
8591
.then(() => register.innerHTML = "<h3>✅ You signed in</h3>")
86-
.catch((error) => alert(error));
92+
.catch((error) => {
93+
submitButton.disabled = false;
94+
submitButton.style.cursor = "";
95+
submitButton.textContent = originalLabel;
96+
alert(error);
97+
});
8798
};
8899
const register = document.getElementById("{{ $course }}")
89100
register.addEventListener("submit", handleSubmit);

0 commit comments

Comments
 (0)