jQuery .ready() for infopath form?

Vap0r picture Vap0r · Jul 28, 2011 · Viewed 10.7k times · Source

I have an infopath form that I want to modify via jQuery. The only problem is that it loads after the pages DOM loads, so jQuery's standard $(document).ready(handler); won't work here. My question is is there any way to pull a $(infopath).ready(handler); of some sort, or a way to maybe wait for the infopath form to get done loading, without just using a standard setTimeout().

EDIT 1: So you have more information, the jQuery is within a Content Editor Web Part (CEWP), and the Infopath form is within an Infopath Form Viewer Web Part.

I know using jQuery or javascript with infopath isn't a standard practice, it unfortunately is a necessary one in this situation due to non-ideal functionality from infopath repeated option controls, discussed further in this question.

EDIT 2: From what I can tell, and I may very well be wrong, sharepoint has a js file called core.js, this seems to have functionality for loading, via AJAX, an infopath form into the page. Is there any way I can set a jQuery function to act after a remote javascript file finishes execution?

Answer

zielonyplot picture zielonyplot · Jan 24, 2012

Try like this: In FormServer.aspx, just above </body>, put this:

<script type="text/javascript">
    _InfoPath.OnLoad2 = function() {
        _InfoPath.OnLoad();
        //Here I will put my custom javascript code, which will be invoked after loading InfoPath form
    }
    window.onload = _InfoPath.OnLoad2;
</script>

My answer also here: How to check if InfoPath form was loaded (in javascript)