diff --git a/.changeset/tidy-zebras-begin.md b/.changeset/tidy-zebras-begin.md new file mode 100644 index 0000000000..cefbf2acfd --- /dev/null +++ b/.changeset/tidy-zebras-begin.md @@ -0,0 +1,5 @@ +--- +'svelte': minor +--- + +feat: support `defaultValue/defaultChecked` for inputs diff --git a/documentation/docs/03-template-syntax/11-bind.md b/documentation/docs/03-template-syntax/11-bind.md index 7dd03a6b04..975135f824 100644 --- a/documentation/docs/03-template-syntax/11-bind.md +++ b/documentation/docs/03-template-syntax/11-bind.md @@ -53,6 +53,22 @@ In the case of a numeric input (`type="number"` or `type="range"`), the value wi If the input is empty or invalid (in the case of `type="number"`), the value is `undefined`. +If an `` has a `defaultValue` and is part of a form, it will revert to that value instead of the empty string when the form is reset. Note that for the initial render the value of the binding takes precedence unless it is `null` or `undefined`. + +```svelte + + +
+ + +
+``` + +> [!NOTE] +> Use reset buttons sparingly, and ensure that users won't accidentally click them while trying to submit the form. + ## `` Checkbox and radio inputs can be bound with `bind:checked`: @@ -64,16 +80,29 @@ Checkbox and radio inputs can be bound with `bind:checked`: ``` +If an `` has a `defaultChecked` attribute and is part of a form, it will revert to that value instead of `false` when the form is reset. Note that for the initial render the value of the binding takes precedence unless it is `null` or `undefined`. + +```svelte + + +
+ + +
+``` + ## `` Inputs that work together can use `bind:group`. ```svelte @@ -146,6 +175,16 @@ When the value of an ` + + + +``` + ## `