diff --git a/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_create_form.svelte b/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_create_form.svelte index 128c0bec..6929242f 100644 --- a/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_create_form.svelte +++ b/src/routes/events/[event_id]/(badges)/badges/ae_comp__badge_create_form.svelte @@ -15,12 +15,17 @@ interface Props { // Fallback badge type list used only when no template is loaded yet or the selected // template has no badge_type_list defined. +// Keep in sync with the list in ae_comp__badge_search.svelte so the create form +// and the search filter always show the same options. +// TODO: drive both from the event's badge template badge_type_list so this is event-agnostic. const default_badge_type_code_li = [ - { code: 'current_member', name: 'Member' }, - { code: 'inactive_member', name: 'Non-Member' }, - { code: 'guest', name: 'Guest' }, - { code: 'ex_all', name: 'Exhibitor' }, + { code: 'attendee', name: 'In-Person Attendee' }, + { code: 'sponsor', name: 'Adapt26 Sponsor' }, { code: 'staff', name: 'Staff' }, + { code: 'guest', name: 'Guest' }, + { code: 'volunteer', name: 'Volunteer' }, + { code: 'member', name: 'Member' }, + { code: 'nonmember', name: 'Non-Member' }, { code: 'test', name: 'Test' } ]; @@ -39,7 +44,7 @@ let affiliations: string = $state(''); let location: string = $state(''); let email: string = $state(''); let allow_tracking: boolean = $state(false); -let badge_type_code: string = $state(''); +let badge_type_code: string = $state('attendee'); // Always pre-select the first template. Every badged event must have at least one template — // without one the badge cannot render. If there's only one we auto-select silently; if there @@ -65,6 +70,19 @@ let badge_type_code_li = $derived.by(() => { } }); +// When the template list loads (async) the derived badge_type_code_li updates. +// Re-apply the preferred default so the select always starts on a real option. +// Preferred: 'attendee'. Fallback: first item in the list. +// Guard: only reset if the current value isn't already in the new list — preserves +// any explicit selection the user made before the template finished loading. +$effect(() => { + const li = badge_type_code_li; + if (!li.length) return; + if (li.some((item) => item.code === badge_type_code)) return; // current value still valid + const preferred = li.find((item) => item.code === 'attendee'); + badge_type_code = preferred?.code ?? li[0].code; +}); + // Only show the name override field if the user explicitly wants to customize it. // The preview below the name fields shows what the badge will display — if that looks // good they don't need to touch this. @@ -241,7 +259,6 @@ let step_label = $derived(