Skip to content

Feat: set form as untouched #12

@gbouteiller

Description

@gbouteiller

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions