-
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
errors message show multiple times when submit with event listener #119
Comments
Base on your code, everytime you "submit" the form, you create a new instance of const validation = new JustValidate('#form');
validation.addField();
document.getElementById("form").addEventListener("submit", (e) => {
e.preventDefault();
validation.revalidate().then(isValid => {
if (isValid) {
// if validate ok then ajax Post call here
}
}
});
// If you want to use async/await:
document.getElementById("form").addEventListener("submit", async (e) => {
e.preventDefault();
const isValid = await validation.revalidate()
if (isValid) {
// if validate ok then ajax Post call here
}
}); |
Hi, |
Hey yeah, as @ceciiiron correctly pointed out, calling |
I want to validate form inside my submit event listener, (instead of DOM load ), so what I do is:
When doing this, the first time I click on button submit, no errors shows even the rules has defined. After that, each time I click the button now I have the errors show on DOM, but repeated many times!
I'm not sure what I did above is correct for the library but I want to follow this pattern to be applied for my project, which is submit called with event listener as normal, then the validation would be applied after. Is it possible?
Please take a look the demonstrate for this error:
https://codesandbox.io/s/just-validate-template-forked-z2gcxb?file=/index.html
The text was updated successfully, but these errors were encountered: