Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2026-06-23 - Form Submitter Loading States
**Learning:** Native `e.submitter` on `submit` events reliably provides the button used to submit a form, allowing for dynamic visual loading states without hardcoding button IDs or changing core app logic.
**Action:** Use `e.submitter` to gracefully handle visual loading styles (disabled, opacity, cursor) during async form submissions.
34 changes: 34 additions & 0 deletions web-demo/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ class ClimaAI {
const email = document.getElementById('loginEmail').value;
const password = document.getElementById('loginPassword').value;

const submitBtn = e.submitter;
let originalContent = '';
if (submitBtn) {
originalContent = submitBtn.innerHTML;
submitBtn.innerHTML = '⏳ Loading...';
submitBtn.disabled = true;
submitBtn.style.opacity = '0.7';
submitBtn.style.cursor = 'not-allowed';
}

try {
this.showToast('Logging in...', 'info');
const response = await api.login(email, password);
Expand All @@ -155,6 +165,13 @@ class ClimaAI {
this.checkSubscription();
} catch (error) {
this.showToast(error.message || 'Login failed', 'error');
} finally {
if (submitBtn) {
submitBtn.innerHTML = originalContent;
submitBtn.disabled = false;
submitBtn.style.opacity = '';
submitBtn.style.cursor = '';
}
}
}

Expand All @@ -164,6 +181,16 @@ class ClimaAI {
const email = document.getElementById('registerEmail').value;
const password = document.getElementById('registerPassword').value;

const submitBtn = e.submitter;
let originalContent = '';
if (submitBtn) {
originalContent = submitBtn.innerHTML;
submitBtn.innerHTML = '⏳ Loading...';
submitBtn.disabled = true;
submitBtn.style.opacity = '0.7';
submitBtn.style.cursor = 'not-allowed';
}

try {
this.showToast('Creating account...', 'info');
const response = await api.register(email, password, name);
Expand All @@ -174,6 +201,13 @@ class ClimaAI {
this.checkSubscription();
} catch (error) {
this.showToast(error.message || 'Registration failed', 'error');
} finally {
if (submitBtn) {
submitBtn.innerHTML = originalContent;
submitBtn.disabled = false;
submitBtn.style.opacity = '';
submitBtn.style.cursor = '';
}
}
}

Expand Down