Replies: 1 comment 11 replies
-
what if you combine that validation logic into one which contains both async and sync validation and returns an error message accordingly? validate: (value) => {
if (Array.isArray(value)) {
return await validation()
}
return regularValidation()
} |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Because previous ticket (#888) was closed and there was still discussion about the problem in common case where you are validating new name with synchronous and also with asynchronous validation which is debounced. I am reopening discussion with the @martdavidson text where he described behaviour of this problem.
@bluebill1049 Can you take another look at this?
The synchronous validation returns false, and an error is shown. Then asynchronous validation resolves and returns true. The error state is now cleared.
Your codesandbox example doesn't have a synchronous validator. Something like:
unique
will always resolve afterspecialCharacters
, so it doesn't matter what the result ofspecialCharacters
was,unique
's result will always overwrite it.In this case, if I enter
Bill$
,specialCharacters
fails and shows an error, andunique
is not called withBill$
because the criteria is set tofirstErrorFound
. Butunique
will fire with justBill
at this point, because that was the last value it was called with, and the debounce delay is triggered.So one path I went down was to call
getValues()
inside ofcheckForUserWithSameDisplayName
to get the value of thedisplayName
field at the time that the debounce triggers and then callmeetsAlphaNumbericRequirement()
again at the top of that function like so:This works, but then the
type
of the error isunique
, notspecialCharacters
, if you care about that.Ideally there'd be a way to maybe return undefined from a validator, which would act as though it had never been called, and the previous state of the form would remain.
Originally posted by @martdavidson in #888 (comment)
Beta Was this translation helpful? Give feedback.
All reactions