-
Notifications
You must be signed in to change notification settings - Fork 91
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
fix: revalidateField does not trigger promise validation directly #112
Comments
I think that the revalidateField method should perform all validation unconditionally because it is checked at a specific point the developer wants. revalidateField(fieldSelector) {
if (typeof fieldSelector !== "string" && !isElement(fieldSelector)) {
throw Error(
`Field selector is not valid. Please specify a string selector or a valid DOM element.`
);
}
const key = this.getKeyByFieldSelector(fieldSelector);
if (!key || !this.fields[key]) {
console.error(`Field not found. Check the field selector.`);
return Promise.reject();
}
return new Promise((resolve) => {
// AS-IS
// this.validateField(key, true).finally(() => {
// TO-BE
this.validateField(key, false).finally(() => {
this.clearFieldStyle(key);
this.clearFieldLabel(key);
this.renderFieldError(key, true);
resolve(!!this.fields[key].isValid);
});
});
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In some cases we want to validate a particular form field on an user action first without validating all form fields. And do final validation on fomr submit.
As for an exemple you have a promo code field you want to validate when the user click on a "Apply" button this will trigger a
fetch
(withPromise
)validator
and only validate the field containing the promo code.In this case I try using
revalidateField
but it seems to not run the promise and always returntrue
.My full example :
The only workaround I found is to use directly
validateField
withafterInputChanged
atfalse
.Like so :
Do I did something wrong, or is that wanted from
revalidateField
?The text was updated successfully, but these errors were encountered: