Auto-fill student email from name using DOMAIN env var on blur

This commit is contained in:
Ian Gulliver
2026-02-15 19:45:41 -08:00
parent 9620ab1990
commit 3c7b651bcd

View File

@@ -1,5 +1,6 @@
import { init, logout, api } from '/app.js';
const DOMAIN = '{{.env.DOMAIN}}';
const tripID = location.pathname.split('/').pop();
const profile = await init();
@@ -461,7 +462,16 @@ async function addStudent() {
document.getElementById('add-student-btn').addEventListener('click', addStudent);
document.getElementById('new-student-name').addEventListener('keydown', (e) => { if (e.key === 'Enter') addStudent(); });
document.getElementById('new-student-email').addEventListener('keydown', (e) => { if (e.key === 'Enter') addStudent(); });
await loadStudents();
await customElements.whenDefined('wa-button');
document.body.style.opacity = 1;
if (DOMAIN) {
document.getElementById('new-student-name').addEventListener('blur', () => {
const emailInput = document.getElementById('new-student-email');
if ((emailInput.value || '').trim()) return;
const name = (document.getElementById('new-student-name').value || '').trim();
const parts = name.toLowerCase().split(/\s+/);
if (parts.length >= 2) emailInput.value = parts.join('.') + '@' + DOMAIN;
});
}