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

Feat: set form as untouched #12

Open
gbouteiller opened this issue Feb 15, 2023 · 0 comments
Open

Feat: set form as untouched #12

gbouteiller opened this issue Feb 15, 2023 · 0 comments

Comments

@gbouteiller
Copy link

Hello again :),
Would it be possible to add a method to the form store to make all the fields untouched. The use case behind it is to reset the form after a successful submit.
For now, this is a way of doing it :

<script lang="ts">
const fields: HTMLElement[] = [];
const initialData = {forename: '', surname: ''};
let formData = initialData;

const onSubmit = () => {
  /*... */
  formData = initialData;
  fields.forEach((field) => delete field.dataset.touched);
};
</script>

<form use:form on:submit|preventDefault={onSubmit}>
  <input type="text" use:forename bind:this={fields[0]} value={formData.forename}  />
  <input type="text" use:surname bind:this={fields[1]} value={formData.surname}  />
</form>
@gbouteiller gbouteiller changed the title Feat: make form untouched Feat: set form as untouched Feb 15, 2023
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

No branches or pull requests

1 participant