Open gbouteiller opened 1 year ago
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>
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 :