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

OnChange (handleChange func)

Open arensade opened this issue 3 years ago • 2 comments

Hi, I'm curious what is exactly handleChange in example page

When we remove on:change={handleChange} still getting changes on submit function.

arensade avatar Apr 20 '22 14:04 arensade

If you have bind:value={$form.someValue} on your form field, then the form will still get updated when the field changes.

Therefore, it looks like handleChange is not necessary.

However, handleChange both changes the value of the form field and it runs validation on the field instantly. It requires a name or id field on the form field to work.

When you use bind:value as well as handleChange, I guess the value is technically being updated twice -- once by Svelte and once by the forms lib. As such, you could argue that bind:value={$form.someValue} should be changed to value={$form.someValue in the examples.

dlebech avatar May 12 '22 14:05 dlebech

See also this issue which describes the same thing: https://github.com/tjinauyeung/svelte-forms-lib/issues/159#issue-1163956097

dlebech avatar May 12 '22 14:05 dlebech