-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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: take form resets into account for two way bindings #10617
Conversation
When resetting a form, the value of the inputs within it get out of sync with the bound value of those inputs. This PR introduces a reset listener on the parent form to reset the value in that case closes #2659
🦋 Changeset detectedLatest commit: 2ee1aff 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 |
There can be many; |
I hope the cross-posting isn't bothersome. But please consider #9230 as well. I really don't like React's solution to this problem. (Does it work with progressive enhancement? My understanding is that it does not. And for tools like SvelteKit, which argues for progressive enhancement in their docs, this is an important consideration.) So I don't think taking React's approach (e.g., with Solid may give some insight on a potential solution. They basically have a directive syntax that says, "This is a raw HTML attribute, not a JS property". They also have something similar for using JS properties only. (Both arguably have use cases.) The It's possible that there are other progressive-enhancement-related bugs that come from relying on JS properties instead of HTML attributes. Having a way to use pure HTML would automatically solve those problems (including the problem that this PR is trying to solve). Any solution that solely relies on JS properties will always have deficiencies in progressive enhancement, because it inherently assumes that JavaScript is accessible to the end user. (Currently, Remix beats SvelteKit here because of how Svelte behaves with form controls.) |
Marking this as ready for review - the default value discussion can happen separately (though I think we should talk about it sooner rather than later). |
When resetting a form, the value of the inputs within it get out of sync with the bound value of those inputs. This PR introduces a reset listener on the parent form to reset the value in that case
closes #2659
Not ready yet because this needs more thought with respect to how the default value is determined, and how a user is able to set it. HTML is weird in that regard because
value
attribute does setdefaultValue
at the same time, but that one's already occupied bybind:value
. You can setdefaultValue
only through JavaScript. It might be best to special-case this attribute on inputs and make it set the default value (also needs to take SSR into account)defaultChecked
selected
attribute on one of the options tells which one is the default value. But in SSR this also tells the current value, so we can't use that. One can also use thevalue
attribute on aselect
for that, but that's occupied by thebind:value
binding. So in this case it might make the most sense and follow React by allowingdefaultValue
on a select even if that property doesn't actually exist on that elementBefore 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