← Back to patterns

Input types

Radios, checkbox groups, multi-selects, ranges and more with typed values

Pattern Usage:

// radio: value + checked
{#each ['public', 'team', 'private'] as option}
  <input {...f.visibility.as('radio', option)} />
{/each}

// checkbox group → string[]
{#each tags as tag}
  <input {...f.tags.as('checkbox', tag)} />
{/each}

// single checkbox → boolean (schema: z.boolean().default(false))
<input {...f.notify.as('checkbox')} />

<select {...f.languages.as('select multiple')}>…</select>
<input {...f.volume.as('range', 60)} />   // → number
<input {...f.releaseDate.as('date')} />
<input {...f.accent.as('color', '#ff3e00')} />

Live Demo:

Visibility (radio)
Tags (checkbox group → string[])

Parsed on the server

Submit to see the typed data the handler received.

How it works: .as(type) only offers types that match the schema: a z.number() field accepts number and range, a string[] accepts checkbox groups and select multiple. Numbers and booleans are coerced before validation, so the handler gets real types, not strings.

Radios and checkbox groups need the option value as the second argument; the third sets the initial checked state. Browsers send nothing for unchecked boxes and empty selects, so those fields need a .default(...) in the schema.