sveltejs / sveltejs/kit

Field value retrieved from `form()` is initially empty

Open
#14,676 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

forms
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Update: Seems to apply to all form fields.

<script lang="ts">
  import { addId } from './ids.remote';

  console.log(addId.fields.checkbox.value());
  console.log(addId.fields.checkbox.set(true));
</script>

<input {...addId.fields.checkbox.as('checkbox')} />

Logs on both the server and the client:

undefined
true
Describe the bug

Despite windows being visually selected in the <select>, the os.value() starts of as an empty string.

<script lang="ts">
  import { FormSchema, osArray } from './ids';
  import { addId } from './ids.remote';
</script>

<form {...addId.preflight(FormSchema)} oninput={() => addId.validate()}>
  <label>
    <span>Operating System</span>
    <select {...addId.fields.os.as('select')}>
      <!-- eslint-disable-next-line svelte/require-each-key -->
      {#each osArray as os}
        <option>{os}</option>
      {/each}
    </select>
  </label>
  <p>{addId.fields.os.value()}</p>
</form>
// ids.remote.ts
import { form } from '$app/server';
import { FormSchema } from './ids';
export const addId = form(FormSchema, () => {});
// ids.ts
import { object, picklist } from 'valibot';
export const osArray = ['windows', 'mac', 'linux'] as const;
export const FormSchema = object({ os: picklist(osArray) });

It is updated only when the user switches the value.

Explicitly selecting the 1st item does not fix the issue.

{#each osArray as os, index}
  <option selected={!index}>{os}</option>
{/each}
Reproduction
Logs

System Info
System:
  OS: Windows 11 10.0.26100
  CPU: (8) x64 Intel(R) Core(TM) Ultra 7 258V
  Memory: 4.75 GB / 31.48 GB
Binaries:
  Node: 24.10.0 - C:\Users\hyunb\AppData\Local\fnm_multishells\14572_1760058974054\node.EXE
  Yarn: 1.22.22 - C:\Users\hyunb\AppData\Local\fnm_multishells\14572_1760058974054\yarn.CMD
  npm: 11.6.1 - C:\Users\hyunb\AppData\Local\fnm_multishells\14572_1760058974054\npm.CMD
  pnpm: 10.18.1 - C:\Users\hyunb\AppData\Local\fnm_multishells\14572_1760058974054\pnpm.CMD
  Deno: 2.4.0 - C:\Users\hyunb\.deno\bin\deno.EXE
Browsers:
  Chrome: 141.0.7390.66
  Edge: Chromium (140.0.3485.54)
  Firefox: 143.0.4 - C:\Program Files\Mozilla Firefox\firefox.exe
npmPackages:
  @sveltejs/adapter-auto: ^6.1.1 => 6.1.1
  @sveltejs/kit: ^2.46.4 => 2.46.4
  @sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.1
  svelte: ^5.39.11 => 5.39.11
  vite: ^7.1.7 => 7.1.7
Severity

annoyance

Additional Information

Related https://github.com/sveltejs/kit/issues/14667

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction and compare the Svelte form markup with ids.remote.ts and ids.ts. Trace the initial state of addId.fields values on both server and client, then verify that select and checkbox fields expose their initial values before user interaction. Done means the reported initial-value cases work without requiring a change event.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
full-stack
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.