fix(badges): cancel edit state on field switch, not just on explicit cancel

toggle_field only changed active_field — it never called cancel_field for the
previously open field. Unsaved typed values stayed in edit_full_name_override etc.,
so reopening a field would show the stale typed value and re-apply it to the badge
preview, even though the user had already moved on.

New logic: capture was_open, always call cancel_field for the current field (resets
edit vars + sets active_field = null), then open the new field if it wasn't the one
being closed. Closing a field by re-clicking its pencil now also discards unsaved state,
consistent with the explicit [X] button behavior.

Also: add global placeholder CSS fix to TODO__Agents.md (scoped workaround already
in ae_comp__badge_print_controls; long-term fix belongs in app.css or theme file).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-04-14 16:55:22 -04:00
parent 7733ef8708
commit 126eb77be2
2 changed files with 33 additions and 1 deletions

View File

@@ -342,7 +342,19 @@ function font_size_reset(
let active_field: string | null = $state(null);
function toggle_field(key: string) {
active_field = active_field === key ? null : key;
// Capture whether the caller is closing the field that's already open.
const was_open = active_field === key;
// Always cancel the current field before switching — discards any unsaved edit
// state so stale typed values don't bleed into the badge preview after the
// accordion closes. The explicit [X] button calls cancel_field directly;
// clicking away to another field (or re-clicking the pencil) must do the same.
if (active_field) {
cancel_field(active_field); // resets edit vars + sets active_field = null
}
if (!was_open) {
active_field = key; // open the new field
}
// If was_open: active_field stays null — the field is now closed.
}
// --- Editable field state ---