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

Support multiple forms in the same page #100

Open
Francesco-M opened this issue Dec 12, 2023 · 0 comments
Open

Support multiple forms in the same page #100

Francesco-M opened this issue Dec 12, 2023 · 0 comments

Comments

@Francesco-M
Copy link

Francesco-M commented Dec 12, 2023

I'm trying to use Pristine dynamically, so I have 2 forms on the same page, I loop them through the class and then dynamically initialise them with Pristine. But the last one always works and never the first. I think that maybe the last initilisation goes to svorascribing the previous ones.

var forms = document.getElementsByClassName('my-form');
 for(let form of forms) { 
	var pristine = new Pristine(form);
         form.addEventListener('submit', function(e) {
                e.preventDefault(); 
                     //  on this point works only the second one, the first one return always false,
                    // if I have only the first one in the page, it works
                   // So  pristine.validate(); returns alwasys false for the first one 
		var valid = pristine.validate();
		if(valid) { 
				.......
		} //end-valid-if
	}); //end-addEventListener
} //end-for
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant