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

[BUG] Field is marked as dirty if checkOnInit is set to true #83

Open
tbydza opened this issue May 31, 2022 · 0 comments
Open

[BUG] Field is marked as dirty if checkOnInit is set to true #83

tbydza opened this issue May 31, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@tbydza
Copy link
Contributor

tbydza commented May 31, 2022

If checkOnInit option of field() function is set to true, the initial validation immediately sets dirty flag to true.
The field is then marked as dirty without any user input or without manually setting a value.

Demo for demonstration: REPL demo

<script>
  import { form, field } from 'svelte-forms';
  import { required } from 'svelte-forms/validators';

  const input1 = field('input1', '', [required()], {checkOnInit: false});
  const input2 = field('input2', '', [required()], {checkOnInit: true});

  input2.subscribe(console.log)
</script>


<section>
  checkOnInit: false
  <input type="text" bind:value={$input1.value}/>
  dirty: {$input1.dirty}
  <br>
  checkOnInit: true
  <input type="text" bind:value={$input2.value}/>
  dirty: {$input2.dirty}
</section>

dirty

@tbydza tbydza added the bug Something isn't working label May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants