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] Stuttering with async validators and text inputs #72

Open
jchanes04 opened this issue Mar 4, 2022 · 3 comments
Open

[BUG] Stuttering with async validators and text inputs #72

jchanes04 opened this issue Mar 4, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@jchanes04
Copy link

When using an async validator, text inputs can experience stuttering while typing. For example, displaying an error when a username is already taken requires making a request to see whether the inputted username is valid or not. I'm not sure what the exact cause is, but it makes it very hard to use async validators.

A potential fix could consist of either debouncing any async validators or canceling any pending promises in favor of evaluating a newer one. For now, I'll just use external validation on the input to check if the username is taken or not.

@jchanes04 jchanes04 added the bug Something isn't working label Mar 4, 2022
@chainlist
Copy link
Owner

Hi @jchanes04,

Thanks for the bug. I manage to reproduce that bug with a high latency connection.
I'll work on a fix ASAP.

Meanwhile, a debounced custom validator would fix your issue

@BrianIto
Copy link

BrianIto commented Jan 8, 2023

@chainlist, it would be awesome to have a specific place for async inside validators so we don't mix things together. The svelte/forms is pretty similar to @angular/forms and maybe the same approach is the best approach (or you can use some tricky magic to see if something is async or not in the same array and do it better).

in @angular/forms we often use this:

myForm = formBuilder.group({ 
    myField: ['Initial Value ', [/* space for validators */], [ /* space for async validators */] ];

And yes, they're debounced and it works pretty well. If you want some help with it I'm happy to contribute. I love svelte and this is by far the best

@dwighson
Copy link

dwighson commented Feb 27, 2023

I wouldn't suggest a deboucer, it will just delay the problem 😅

try this instead:

 <input
   type="text"
   on:keyup={(e) => ($yourcustomfield.value = e.target.value)}         
 />

the docs say that you should bind the value to the variable but for some reason it will change the value in the input field back to the last known value that has been checked, which causes the problem I believe.

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

4 participants