Using Wordpress with Gravity Forms Ajax and Swup JS for dynamic form submissions

For page transitions and AJAX content changes, I have implemented swup.js. However, Gravity forms is not properly handling the AJAX request and the form stops working after transitioning.

To reinitialize my scripts upon page load, I am using the following code snippet:

document.addEventListener('swup:pageView', (event) => {
// insert your code here
})

I am wondering if there is a specific JavaScript function I can use to ensure that Gravity forms are reinitialized with each page transition. I searched the documentation but could not find any relevant information.

Answer №1

Although the post date may seem outdated, a question has recently come to mind that needs addressing. If you have been unable to find a solution, consider utilizing the following code snippet:

Feel free to give this code a try - it monitors any changes made to the body's DOM and can be customized to trigger specific actions:

<script>
    $(document).on('DOMSubtreeModified', 'body', function (el) {
        console.log('Changes detected in body content');
        // Add your initialization code here
    });
</script>

Please let me know if this method proves to be effective for your needs.

Answer №2

I ended up utilizing SwupFormsPlugin along with Contact Form 7 and implemented the following code snippet:

document.addEventListener('DOMContentLoaded', function (event) {
  var domain = window.location.origin // Adjusting link selector to be relative
  var isMobile = window.innerWidth < 800
  if (isMobile) {
  } else {
    var swup = new Swup({
      plugins: [
        new SwupOverlayTheme({
          color: '#eff6fb',
          duration: 3000,
          direction: 'to-bottom',
        }),
        new SwupBodyClassPlugin(),
        new SwupFormsPlugin({ formSelector: 'form.wpcf7-form' }),
        new SwupScrollPlugin({
          doScrollingRightAway: false,
          animateScroll: true,
          scrollFriction: 0.3,
          scrollAcceleration: 0.04,
        }),
      ],
      FORM_SELECTOR: 'form.wpcf7-form',
      LINK_SELECTOR: 'a[href*="'.concat(
        domain,
        '"]:not([data-no-swup]), a[href^="/"]:not([data-no-swup]), a[href^="#"]:not([data-no-swup]), a[xlink\\:href]'
      ),
    })
    swup()
  }
})
function domReady (callback) {
  document.readyState === 'interactive' || document.readyState === 'complete'
    ? callback()
    : document.addEventListener('DOMContentLoaded', callback)
}
export { domReady }

Hope this solution proves beneficial for others as well.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unable to locate the tag using .find() function following the use of .attr() method

I am currently utilizing jQuery in conjunction with node-horseman to interact with a specific page. My approach involves referencing the page's data-id attribute, which I then pass to my application to search for the li element containing this attribu ...

The jQuery target is not able to locate the specified element

Why does this code snippet work in one case: jQuery(this).closest("li").find("p").text(); But when enclosed within a function, it fails to produce the desired result: jQuery.each(words, function(i, v) { jQuery(this).closest("li").find("p").text(); } ...

When attempting to set the keyPath using a variable, an error occurs stating that the keyPath option is not a valid key path

My JSON object, stored in a variable named "jsonObjSuper", is structured like this: { "Watchlist": "My Watchlist", "Instruments": { "instrument1": [ "Company ABC", [ { "snapshotTimeUTC": "2018-11-01T00:00:00", "snapshotTime": "2018/11/ ...

Creating a String Array and linking it to an Input Field

I'm currently working on a code that involves mapping through an array of strings using observables. My objective is to display the value from this array inside an input field. However, despite being able to view the array in the console, I encountere ...

The combination of Node.js module.exports and shorthand ternary operators for conditional statements

Can you explain the purpose of this line 'undefined' != typeof User ? User : module.exports and why is everything enclosed within (function(){})? I am having trouble understanding its significance. This code snippet is extracted from a library f ...

Tips for checking errors during the process of WRITING data to a stream

Currently, I am testing the errors thrown in various sections of the application. The app is designed to transfer a stream from the request (multipart file upload) through encryption to an S3 bucket. While I can successfully simulate an exception in the _ ...

Issue with React app: IconMenu does not expand when clicked

Seeking assistance with a react app and IconMenu from material-ui. I've been researching similar issues extensively but haven't found a solution yet :( In the code below, I am looking to manually trigger the expansion of a menu - this is essenti ...

When using this.$refs in Vue, be mindful that the object may be undefined

After switching to TypeScript, I encountered errors in some of my code related to: Object is possibly 'undefined' The version of TypeScript being used is 3.2.1 Below is the problematic code snippet: this.$refs[`stud-copy-${index}`][0].innerHTM ...

What steps need to be taken to automatically redirect a user to the login page after attempting to execute an AJAX request when the Spring Security

I have a Spring Boot application with Spring Security. I am trying to check if the user is redirected to the login page after the session times out. I have two pages, login and index. On the index page, requests are made using Ajax. When I open the index ...

Dealing with errors in jQuery when handling JSON

Currently, I am utilizing jQuery's ajax feature to transmit JSON to a PHP script and then acquire a JSON set of values for processing on the front end. The PHP script is properly sending the JSON data, and I am successfully able to display the JSON o ...

Dynamically insert a new row into an HTML table using AJAX and refresh the table with .load method

I am facing an issue with my HTML table that loads data dynamically through a PHP snippet containing SQL queries. There is a Select option and a button on the table to add a new row, which triggers an AJAX procedure to send the data to PHP for insertion in ...

Encountering a npm failure during the installation process of polymer

I'm currently attempting to test sensors using HTML and JavaScript, following the example provided here. However, I encountered an issue when trying to install polymer as instructed in the readme file. The error I received is as follows: kupu@kupu:~/ ...

Variable assigned by Ajax no longer accessible post-assignment

Recently, I've written a script to fetch data from a SQL database and now I'm in the process of creating a JS wrapper for it. Utilizing certain functions, I call the script and extract information from the DB as soon as it becomes available. var ...

Modify the href value by matching it with the parent div attribute

I am working on an HTML project <div class="1" style="" title="NeedthisText TextIDontneed"> <div class="2> <div class="3"> <a target="_blank" href="/NeedToChange/DispForm.aspx?ID=1"></a> </div> </div> &l ...

Once the vue-cli has deployed to the server, the server's requested image path is now located in /dist/ folder

Issue with Image Loading: While the demo successfully loads all resources and uploads images correctly, there is an issue where an extra /dist/ is being requested for image paths, resulting in a 404 error. Demo Link: https://i.sstatic.net/XjniG.png Con ...

Here is a unique rewrite: "Utilize jQuery to extract all data-id and amount from an HTML page, then send it through an

Is there a way to retrieve the data-id and amount values from this HTML page using jQuery? Once I have gathered that information, I would like to store it in an array and then submit it via an AJAX call. It's important to note that this is a Laravel p ...

Is there a way for me to determine which class has been selected using jQuery and JavaScript?

I created a list containing various links: <li class="link-1"><a href="#">One</a></li> <li class="link-2"><a href="#">Two</a></li> <li class="link-3"><a href="#">Three</a></li> .. Wh ...

Tips on how to efficiently wrap content within a column layout, and to seamlessly shrink it if necessary

I recently encountered an issue where I am attempting to create a three-column layout with each column filled with a dynamic number of divs (boxes) ranging from 5 to 15, each with its own height based on its content. These divs are expected to: 1) Be dis ...

Utilizing the power of Jquery, Ajax, and ASP.NET web methods

When utilizing query ajax to invoke a webmethod in an ASP.NET page, it functions smoothly with a POST HTTP request. However, if a GET request is utilized, the Page_Load event is triggered instead of the webmethod. Any suggestions for resolving this issue? ...

The onClick function is failing to work properly, and I need to pass the value of 'cid' based on the result of the button

Is it possible to pass the 'courseid' to local storage when a button is clicked? I am having trouble with onclick not working. How can I retrieve the relevant 'courseid' in the onclick function based on the button clicked? handleClick ...