This commit is contained in:
larssand
2026-03-27 19:07:19 +01:00
parent 05e0bf0c1f
commit f5be5b57ad
2 changed files with 56 additions and 28 deletions

View File

@@ -254,12 +254,18 @@ export function renderEventManagerView(context) {
document.getElementById("sessionForm")?.addEventListener("submit", (e) => { document.getElementById("sessionForm")?.addEventListener("submit", (e) => {
e.preventDefault(); e.preventDefault();
const form = new FormData(e.currentTarget); const formNode = e.currentTarget;
if (!(formNode instanceof HTMLFormElement)) {
return;
}
const form = new FormData(formNode);
const typeField = formNode.querySelector('[name="type"]');
const selectedType = typeField instanceof HTMLSelectElement ? typeField.value : String(form.get("type") || "");
state.sessions.push(normalizeSession({ state.sessions.push(normalizeSession({
id: uid("session"), id: uid("session"),
eventId, eventId,
name: String(form.get("name")).trim(), name: String(form.get("name")).trim(),
type: String(form.get("type")), type: selectedType,
durationMin: Number(form.get("durationMin")), durationMin: Number(form.get("durationMin")),
followUpSec: Math.max(0, Number(form.get("followUpSec") || 0) || 0), followUpSec: Math.max(0, Number(form.get("followUpSec") || 0) || 0),
startMode: String(form.get("startMode") || "mass"), startMode: String(form.get("startMode") || "mass"),
@@ -350,7 +356,13 @@ export function renderEventManagerView(context) {
if (!editingSession) { if (!editingSession) {
return; return;
} }
const form = new FormData(event.currentTarget); const formNode = event.currentTarget;
if (!(formNode instanceof HTMLFormElement)) {
return;
}
const form = new FormData(formNode);
const typeField = formNode.querySelector('[name="type"]');
const selectedType = typeField instanceof HTMLSelectElement ? typeField.value : String(form.get("type") || editingSession.type);
const cleanedName = String(form.get("name") || "").trim(); const cleanedName = String(form.get("name") || "").trim();
const cleanedDuration = Number(form.get("durationMin") || editingSession.durationMin || 5) || 0; const cleanedDuration = Number(form.get("durationMin") || editingSession.durationMin || 5) || 0;
if (!cleanedName) { if (!cleanedName) {
@@ -363,7 +375,7 @@ export function renderEventManagerView(context) {
} }
setFormError("sessionEditError", ""); setFormError("sessionEditError", "");
editingSession.name = cleanedName; editingSession.name = cleanedName;
editingSession.type = String(form.get("type") || editingSession.type); editingSession.type = selectedType;
editingSession.durationMin = Math.max(1, cleanedDuration); editingSession.durationMin = Math.max(1, cleanedDuration);
editingSession.followUpSec = Math.max(0, Number(form.get("followUpSec") || 0) || 0); editingSession.followUpSec = Math.max(0, Number(form.get("followUpSec") || 0) || 0);
editingSession.startMode = normalizeStartMode(String(form.get("startMode") || editingSession.startMode || "mass")); editingSession.startMode = normalizeStartMode(String(form.get("startMode") || editingSession.startMode || "mass"));
@@ -496,7 +508,11 @@ export function renderEventManagerView(context) {
if (showTeamsSection) { if (showTeamsSection) {
document.getElementById("teamForm")?.addEventListener("submit", (e) => { document.getElementById("teamForm")?.addEventListener("submit", (e) => {
e.preventDefault(); e.preventDefault();
const form = new FormData(e.currentTarget); const formNode = e.currentTarget;
if (!(formNode instanceof HTMLFormElement)) {
return;
}
const form = new FormData(formNode);
const name = String(form.get("teamName") || "").trim(); const name = String(form.get("teamName") || "").trim();
const driverIds = form.getAll("teamDriverIds").map(String).filter(Boolean); const driverIds = form.getAll("teamDriverIds").map(String).filter(Boolean);
const carIds = form.getAll("teamCarIds").map(String).filter(Boolean); const carIds = form.getAll("teamCarIds").map(String).filter(Boolean);
@@ -559,7 +575,11 @@ export function renderEventManagerView(context) {
if (!editingTeam) { if (!editingTeam) {
return; return;
} }
const form = new FormData(submitEvent.currentTarget); const formNode = submitEvent.currentTarget;
if (!(formNode instanceof HTMLFormElement)) {
return;
}
const form = new FormData(formNode);
const name = String(form.get("teamName") || "").trim(); const name = String(form.get("teamName") || "").trim();
const driverIds = form.getAll("teamDriverIds").map(String).filter(Boolean); const driverIds = form.getAll("teamDriverIds").map(String).filter(Boolean);
const carIds = form.getAll("teamCarIds").map(String).filter(Boolean); const carIds = form.getAll("teamCarIds").map(String).filter(Boolean);

View File

@@ -59,7 +59,7 @@ export function renderEventManagerMarkup(context) {
</label> </label>
<label> <label>
${t("events.session_type_label")} ${t("events.session_type_label")}
<select name="type"> <select id="sessionCreateType" name="type">
${sessionTypeChoices.map((s) => `<option value="${s}">${getSessionTypeLabel(s)}</option>`).join("")} ${sessionTypeChoices.map((s) => `<option value="${s}">${getSessionTypeLabel(s)}</option>`).join("")}
</select> </select>
<small>${t(sessionTypeHintKey)}</small> <small>${t(sessionTypeHintKey)}</small>
@@ -306,32 +306,40 @@ export function renderEventManagerMarkup(context) {
<div class="panel-body"><p class="hint">${t("events.team_form_drivers")}</p></div> <div class="panel-body"><p class="hint">${t("events.team_form_drivers")}</p></div>
${teamDriverPool.fallback ? `<div class="panel-body"><p class="hint">${t("events.team_driver_fallback")}</p></div>` : ""} ${teamDriverPool.fallback ? `<div class="panel-body"><p class="hint">${t("events.team_driver_fallback")}</p></div>` : ""}
<div class="panel-body check-grid"> <div class="panel-body check-grid">
${teamDriverPool.drivers ${
.map( teamDriverPool.drivers.length
(driver) => ` ? teamDriverPool.drivers
<label class="check-card"> .map(
<input type="checkbox" name="teamDriverIds" form="teamForm" value="${driver.id}" /> (driver) => `
<span>${escapeHtml(driver.name)}${driver.transponder ? ` (${escapeHtml(driver.transponder)})` : ""}</span> <label class="check-card">
</label> <input type="checkbox" name="teamDriverIds" form="teamForm" value="${driver.id}" />
` <span>${escapeHtml(driver.name)}${driver.transponder ? ` (${escapeHtml(driver.transponder)})` : ""}</span>
) </label>
.join("")} `
)
.join("")
: `<p class="hint">${t("common.no_entries")}</p>`
}
</div> </div>
</section> </section>
<section class="panel"> <section class="panel">
<div class="panel-header"><h3>${t("events.team_cars")}</h3></div> <div class="panel-header"><h3>${t("events.team_cars")}</h3></div>
<div class="panel-body"><p class="hint">${t("events.team_form_cars")}</p></div> <div class="panel-body"><p class="hint">${t("events.team_form_cars")}</p></div>
<div class="panel-body check-grid"> <div class="panel-body check-grid">
${state.cars ${
.map( state.cars.length
(car) => ` ? state.cars
<label class="check-card"> .map(
<input type="checkbox" name="teamCarIds" form="teamForm" value="${car.id}" /> (car) => `
<span>${escapeHtml(car.name)} (${escapeHtml(car.transponder || "-")})</span> <label class="check-card">
</label> <input type="checkbox" name="teamCarIds" form="teamForm" value="${car.id}" />
` <span>${escapeHtml(car.name)} (${escapeHtml(car.transponder || "-")})</span>
) </label>
.join("")} `
)
.join("")
: `<p class="hint">${t("common.no_entries")}</p>`
}
</div> </div>
</section> </section>
</div> </div>
@@ -778,7 +786,7 @@ export function renderEventManagerMarkup(context) {
</label> </label>
<label> <label>
${t("events.session_type_label")} ${t("events.session_type_label")}
<select name="type"> <select id="sessionEditType" name="type">
${sessionTypeChoices.map( ${sessionTypeChoices.map(
(item) => `<option value="${item}" ${item === editingSession.type ? "selected" : ""}>${getSessionTypeLabel(item)}</option>` (item) => `<option value="${item}" ${item === editingSession.type ? "selected" : ""}>${getSessionTypeLabel(item)}</option>`
).join("")} ).join("")}