Skip to content

Commit fd17209

Browse files
authored
docs: convert picklist options to a const array (#14616)
1 parent 4fc3257 commit fd17209

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

documentation/docs/20-core-concepts/60-remote-functions.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -393,20 +393,23 @@ In the case of `radio` and `checkbox` inputs that all belong to the same field,
393393
import * as v from 'valibot';
394394
import { form } from '$app/server';
395395
// ---cut---
396+
export const operatingSystems = /** @type {const} */ (['windows', 'mac', 'linux']);
397+
export const languages = /** @type {const} */ (['html', 'css', 'js']);
398+
396399
export const survey = form(
397400
v.object({
398-
operatingSystem: v.picklist(['windows', 'mac', 'linux']),
399-
languages: v.optional(v.array(v.picklist(['html', 'css', 'js'])), [])
401+
operatingSystem: v.picklist(operatingSystems),
402+
languages: v.optional(v.array(v.picklist(languages)), []),
400403
}),
401-
(data) => { /* ... */ }
404+
(data) => { /* ... */ },
402405
);
403406
```
404407
405408
```svelte
406409
<form {...survey}>
407410
<h2>Which operating system do you use?</h2>
408411

409-
{#each ['windows', 'mac', 'linux'] as os}
412+
{#each operatingSystems as os}
410413
<label>
411414
<input {...survey.fields.operatingSystem.as('radio', os)}>
412415
{os}
@@ -415,7 +418,7 @@ export const survey = form(
415418

416419
<h2>Which languages do you write code in?</h2>
417420

418-
{#each ['html', 'css', 'js'] as language}
421+
{#each languages as language}
419422
<label>
420423
<input {...survey.fields.languages.as('checkbox', language)}>
421424
{language}
@@ -433,17 +436,17 @@ Alternatively, you could use `select` and `select multiple`:
433436
<h2>Which operating system do you use?</h2>
434437

435438
<select {...survey.fields.operatingSystem.as('select')}>
436-
<option>windows</option>
437-
<option>mac</option>
438-
<option>linux</option>
439+
{#each operatingSystems as os}
440+
<option>{os}</option>
441+
{/each}
439442
</select>
440443

441444
<h2>Which languages do you write code in?</h2>
442445

443446
<select {...survey.fields.languages.as('select multiple')}>
444-
<option>html</option>
445-
<option>css</option>
446-
<option>js</option>
447+
{#each languages as language}
448+
<option>{language}</option>
449+
{/each}
447450
</select>
448451

449452
<button>submit</button>

0 commit comments

Comments
 (0)