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

Multiple updates and inconsistent casting #159

Open
SamMousa opened this issue Mar 9, 2022 · 0 comments
Open

Multiple updates and inconsistent casting #159

SamMousa opened this issue Mar 9, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@SamMousa
Copy link

SamMousa commented Mar 9, 2022

Summary

When creating a form according to the basic example on the website there is some configuration that leads to multiple and inconsistent updates to form values.

<input 
    id="number"
    name="number"
    type="number"
    on:change={handleChange}
    bind:value={$form.number}

The change handler updates the form value, but the 2 way binding does that as well.
Furthermore, when testing the results are not consistent:

  1. Just bind, the form value is an integer.
  2. Just on:change, the form value is a numerical string.
  3. Both: 2 form updates & validations are triggered, the on:change is the last one so the form value is a numerical string.

Steps to reproduce

  • Go to the demo project below
  • Change the 3 inputs using the up and down buttons

Example Project

https://codesandbox.io/s/sleepy-shockley-jns3z9?file=/App.svelte

What is the current bug behavior?

Notice that for the first input, which is set up according to the basic example page, the form value is changed twice and is converted from integer to string.
Further any change on the input should not (need to) lead to 2 updates of the form value.

What is the expected correct behavior?

I'm not sure what the single correct behavior should be. I'm new to Svelte and this form library, but I think that we can at least have some expectations:

  • The code used in the basic example should trigger an update only once per change
  • It should not change the type of a value (I'm aware that in HTML all values are strings), so either we always have strings or we use the cast that is implemented in Svelte's bind mechanics.
@SamMousa SamMousa added the bug Something isn't working label Mar 9, 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

1 participant