#17131·kit

未被触及的远程表单 `<select>` 在 `onchange` 上运行 `validate()` 时呈现为空白

作者: CheHyeonYeong创建于 2026年9月18日更新于 2026年9月18日

schema.ts

typescript
import { object, optional, string } from 'valibot';

export const MreSchema = object({
	picked: optional(string(), ''),
	text: optional(string(), ''),
});

data.remote.ts

typescript
import { form } from '$app/server';
import { MreSchema } from './schema.ts';

export const mreForm = form(MreSchema, async () => {
	return { ok: true };
});

+page.svelte

svelte
<script lang="ts">
	import { mreForm as _mreForm } from './data.remote.ts';
	import { MreSchema } from './schema.ts';

	const uid = $props.id();
	const mreForm = _mreForm.for(uid);
</script>

<form {...mreForm.preflight(MreSchema)} onchange={() => mreForm.validate()}>
	<select {...mreForm.fields.picked.as('select')}>
		<option value="">-- pick --</option>
		<option value="a">A</option>
		<option value="b">B</option>
		<option value="c">C</option>
	</select>
	<input {...mreForm.fields.text.as('text')} placeholder="type here, then blur" />
	<button>submit</button>
</form>

Steps (do not touch the <select>):

  1. The <select> shows -- pick --.
  2. Type into the text input and blur it — this fires onchangevalidate().
  3. The untouched <select> now displays blank (its selectedIndex is -1) instead of -- pick --.

Removing onchange={() => mreForm.validate()} leaves the <select> alone.