gravity forms jQuery.load into modal [closed]

I eventually received a response from the development team who suggested that an iframe was the best approach:

It looks like it is a timing issue. Your form is getting loaded to the DOM after the document has already been loaded, so that will be a problem.
To be honest, with all the JS complexities in Gravity Forms, I am not sure you will be able to get this to work. I would seriously consider using an iframe instead.

In the time that it took for this response to come back I discovered that the div that I was importing using [.load()][1] was missing all the script elements from the original content. This is because, though its not explicitly documented, .load() strips out any inline scripts, so while the markup was present, none of the activation goodness happened.

One solution (which works) is to package the content from the inline scripts by looking at the page source, and package it into a js file which you load via a [jQuery.getScripts()][3] call. In addition to stripping out the <script></script> elements, you may also may want to modify any paths so they are too relative to mitigate migration issues.

The (major) drawback here is that by packaging this script ourselves, it’s no longer takes paramaters from the back end and will likely break when changes are made to the form. It also has baked in a few instances of browser detection.

Due to these limitations, and without a method to dynamically generate these scripts an iframe is really the way to go. That said, it would no doubt be possible to create a custom class that output the scripts – it would largely need to be refactored from the contents of form_display.php as most of what is needed is locked up under private functions. I’ve not found any evidence in my searching of anyone attempting this so far.