Closed rachste closed 6 years ago
Hey. You are thinking in the right direction. Since it 's being loaded dynamically, $('#contact-form')
is being replaced, hence lose its refs.
You will need to tell Validate.js pick up your form again after the Barba replace the new container.
Attach a listener when a new page is ready to tell Validate.js about the new form.
Reading http://barbajs.org/events.html should help you start with ya solution.
Hope that helps. Cheers.
@khaiknievel Can you please give more information. Example: I'm using the Owl Carousel and this need to be reinit on that Events?
Some JavaScript plugins don't have the Reinit function and how can i achive this?
Thanks.
@Uranbold For example.
document.addEventListener('DOMContentLoaded', function () {
$("#contact-form").validate()
})
// Simply re-init.
// The plugin does not need to have the reinit function.
//
// @see http://barbajs.org/events.html
Barba.Dispatcher.on('newPageReady', function(currentStatus, oldStatus, container) {
$("#contact-form").validate()
});
See: http://barbajs.org/events.html
In your example case, simply call the init method for the Owl Carousel.
Hello all!
I'm a newcomer to Javascript, but I think I get what's happening - I'm just unsure of how to go about fixing it myself.
If I access the page directly, e.g. http://mydomain.com/contact/, then everything works as expected.
If the form is loaded using barba, the data submitted through the form is appended to the URL (http://mydomain.com/contact/?name=test&_replyto=test%40test.com&message=test), an email isn't sent out to me, and my success message doesn't load.
I noticed when I access the page directly that
novalidate="novalidate"
is added to<form>
. This doesn't happen when the form is loaded using barba. My thinking is that my custom Javascript for Validate.js isn't picking up my form since it's being loaded dynamically.I tried out a few solutions from the web, but nothing has worked for me, unfortunately. Any help is appreciated!
My Formspree form:
Here's my custom Javascript: