Skip to content
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

fix: Form reset should trigger bindings #9930

Closed
wants to merge 6 commits into from

Conversation

adiguba
Copy link
Contributor

@adiguba adiguba commented Dec 15, 2023

fix #2659

Currently resetting an html form doesn't trigger input bindings.
Example : REPL

This PR make 3 mains changes :

  • It add a __bind attribute on the prototype of HTMLInputElement, HTMLSelectElement and HTMLTextAreaElement.
  • It add an event-listener on <body> for 'reset', that check for a __bind attribute on the form's elements.
  • bind_value(), bind_select_value(), bind_group() and bind_checked() store the handler on the __bind attribute, so it can be called when the form is reset.

Note : I added the 'reset' handler on the init_operations() function, but I'm note sure it's the best place for that...

Same source with this PR : REPL on vercel

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

If necessary I would look into doing a test.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

test & lint produce a lots of error (before my change)

Copy link

changeset-bot bot commented Dec 15, 2023

⚠️ No Changeset found

Latest commit: fd7ae67

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Dec 15, 2023

@adiguba is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

@dummdidumm
Copy link
Member

dummdidumm commented Feb 1, 2024

This is an interesting solution (though we can't eagerly add the document event listener), but I'm not sure we should add this additional code for this edge case. It may be better to add a note in the docs about this.

@dummdidumm
Copy link
Member

Thank you for tackling this, made me think of an alternative which is a little less invasive - closing in favor of #10617

@dummdidumm dummdidumm closed this Feb 23, 2024
@adiguba adiguba deleted the form_reset_bindings branch September 16, 2024 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resetting html form doesn't trigger input bindings
2 participants