Skip to content

Feat: set form as dirty #11

@gbouteiller

Description

@gbouteiller

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>

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