-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: default values for form elements #14289
Conversation
🦋 Changeset detectedLatest commit: d4e836b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
preview: https://svelte-dev-git-preview-svelte-14289-svelte.vercel.app/ this is an automated message |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like <select>
elements aren't being reset correctly? I have to press the reset button twice for the state to update, even though the select itself updates immediately
WIP
closes #8220
closes #9230
This implements default values for form elements. These default values take effect when the
reset
method of the surrounding form is invoked.input
withvalue/checked
it'sdefaultValue/defaultChecked
forno handling forinput
withbind:group
it'schecked
(hydration not working yet, not working for dynamic yet)bind:group
, because too confusing / limitingselect
it'sselected
on theoption
elements (hydration not working yet, not working for dynamic yet)Open questions:
defaultValue/defaultChecked
the value of that takes precedence on the initial render in case thevalue/checked
value isundefined/null
. That also means that in case ofbind:value/checked
the default value will be propagated back to that variable. Ok?bind:group
? It's tricky there because for a group of checkboxes, we currently require an array to be set (else you get runtime errors), and so the value isn't falsy, and the empty array could be on purpose / hard to say if the default checked should take precedence there initiallybind:group
. That binding is kinda special in many ways and withbind:checked={get, set}
we can likely provide a more robust/scalable/working across components solution anywaybind:value
on selects withmultiple
, with same problem as forbind:group
on checkboxesmultiple
the initial selection is ignored, i.e. the array takes precedenceBefore submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint