svelte-forms icon indicating copy to clipboard operation
svelte-forms copied to clipboard

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

Open tbydza opened this issue 3 years ago • 0 comments

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 avatar May 31 '22 08:05 tbydza