Repository navigation
fix: preserve emptied remote number defaults - #16237
vamshikrishnaramasamy wants to merge 1 commit into
Conversation
|
Install the latest version of pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/5e1f2d46e77f47fb2316a57e11d3b8de00e41dc3Open in Note This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed. |
|
…ault only until edited (#16939) Since #16331 moved coercion into `coerce_form_value`, `handle_input` has stored the raw string of every typed value: `fields.value()` reported `'20'` while typing and `200` after a reset, and an emptied number field held `''` instead of `undefined`. Typed values are coerced again, the same way the submitter path already is. That re-exposes #15937: the default passed to `.as(type, default)` was re-applied whenever the field's value became `undefined` or `null`, so an emptied number input, or one cleared with `set()`, snapped back to its default. The default now only applies until the field is dirty. `defaultValue` and `defaultChecked` are unchanged, so reset still restores it. `dirty` is the modified signal from #16208; `touched` would drop the default on a tab-through. It is client-only, so SSR and a failed no-JS submission still render defaults. #16237 keys the same rule on key presence in the model instead. Fixes #15937.
Fixes #15937.
Remote form fields previously rendered their default whenever the backing value was
nullorundefined. Empty number inputs are converted toundefined, so deleting a defaulted number field caused the rendered value to snap back to the default.This distinguishes a missing field from a field that exists with an
undefinedvalue. Missing fields still render defaults, while emptied number fields render as empty strings.Tests:
pnpm --dir packages/kit exec vitest --config kit.vitest.config.js run src/runtime/form-utils.spec.jspnpm --dir packages/kit exec prettier --config ../../.prettierrc --check src/runtime/form-utils.js src/runtime/form-utils.spec.jspnpm --dir packages/kit exec tsc --noEmit --pretty false