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 dirty #11

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

Feat: set form as dirty #11

gbouteiller opened this issue Feb 15, 2023 · 0 comments

Comments

@gbouteiller
Copy link

gbouteiller commented Feb 15, 2023

Hello again :),
Would it be possible to add a method to the form store to set it as dirty (set all its fields as dirty) in order for example to display all invalid fields at the same time when clicking on submit?
For now, this is a way of doing it :

<script lang="ts">
const fields: HTMLElement[] = [];

const invalidate = () => fields.forEach((field) => {
  field.focus();
  field.blur();
});

const onSubmit = () => {
  if (!$form.valid) return invalidate();
  /*... */
};
</script>

<form use:form on:submit|preventDefault={onSubmit}>
  <input type="text" use:forename bind:this={fields[0]}  />
  <input type="text" use:surname bind:this={fields[1]}  />
</form>
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