fix(badges): always pre-select first template on badge create
Every badged event must have a template — without one the badge cannot render. Changed auto-select from === 1 to >= 1 so multi-template events also get a default (first template). Added an error message and disabled submit when no templates are configured at all. Removed blank "-- Select Template --" option so the form never submits with null. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -41,12 +41,14 @@ let email: string = $state('');
|
||||
let allow_tracking: boolean = $state(false);
|
||||
let badge_type_code: string = $state('');
|
||||
|
||||
// Auto-select the first template when only one is available; otherwise let the user pick.
|
||||
// event_badge_template_id is sent to the API so the badge renders with the correct layout.
|
||||
// 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
|
||||
// are multiple the dropdown lets the user switch, but we never start with no selection.
|
||||
// The !selected_template_id guard prevents a reactive re-fire from overriding a user's pick.
|
||||
let selected_template_id: string = $state('');
|
||||
$effect(() => {
|
||||
if (template_li.length === 1 && template_li[0].event_badge_template_id) {
|
||||
selected_template_id = template_li[0].event_badge_template_id;
|
||||
if (template_li.length >= 1 && !selected_template_id) {
|
||||
selected_template_id = template_li[0].event_badge_template_id ?? '';
|
||||
}
|
||||
});
|
||||
|
||||
@@ -214,13 +216,17 @@ let step_label = $derived(
|
||||
<span class="label-text">Email</span>
|
||||
<input type="email" bind:value={email} class="input" placeholder="jane@example.com" />
|
||||
</label>
|
||||
{#if template_li.length > 1}
|
||||
{#if template_li.length === 0}
|
||||
<!-- No templates configured — badge cannot render without one. Block submission. -->
|
||||
<p class="text-error-600 dark:text-error-400 text-sm font-medium">
|
||||
No badge templates are configured for this event. Set up a template before creating badges.
|
||||
</p>
|
||||
{:else if template_li.length > 1}
|
||||
<!-- Template selector — only shown when the event has multiple templates.
|
||||
Single-template events auto-select; the selector would just add noise. -->
|
||||
Single-template events auto-select silently; the selector would just add noise. -->
|
||||
<label class="label">
|
||||
<span class="label-text">Badge Template</span>
|
||||
<select bind:value={selected_template_id} class="select">
|
||||
<option value="">-- Select Template --</option>
|
||||
{#each template_li as tmpl (tmpl.event_badge_template_id)}
|
||||
<option value={tmpl.event_badge_template_id}>{tmpl.name}</option>
|
||||
{/each}
|
||||
@@ -275,7 +281,7 @@ let step_label = $derived(
|
||||
<button
|
||||
type="submit"
|
||||
class="btn preset-filled-primary"
|
||||
disabled={is_submitting || !given_name || !family_name}>
|
||||
disabled={is_submitting || !given_name || !family_name || template_li.length === 0}>
|
||||
Create Badge
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user