fix(badges): sync create form badge types with search filter; default to attendee
- default_badge_type_code_li now matches ae_comp__badge_search.svelte list (attendee, sponsor, staff, guest, volunteer, member, nonmember, test) - badge_type_code initializes to 'attendee' (In-Person Attendee) - $effect re-applies preferred default when template badge_type_list loads async, falling back to first item if 'attendee' isn't in the template's list - Remove the blank '-- Select Badge Type --' placeholder option Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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(
|
||||
<label class="label">
|
||||
<span class="label-text">Badge Type</span>
|
||||
<select bind:value={badge_type_code} class="select">
|
||||
<option value="">-- Select Badge Type --</option>
|
||||
{#each badge_type_code_li as item (item.code)}
|
||||
<option value={item.code}>{item.name}</option>
|
||||
{/each}
|
||||
|
||||
Reference in New Issue
Block a user