How to run scripts AFTER SPEasyForms? User Feedback Example

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1687
    hzynst
    Participant

    Hello –

    I’ve see a number of questions asking how to run a script AFTER SPEasyForms …

    In the past, I have used a setTimeout() and waited 2500ms – 3000ms which has worked fairly reliably in my environment …

    Lately, I’ve been placing a specifically named data-containername at the very end of the Form(s) and watching the DOM for when it appears …. then running my scripts/functions … This has proven to work even better than setTimeout() as it is not affected by use of the F12 debug window (which slows everything down – except time itself!).

    In the example below, I have an HTML Snippet with a specific data-containername.

    The javascript/jQuery snippet watches for the existence of this container then executes my localization …

    Hope this helps!

    Example to watch for – created in SPEasyForms Editor placed at end of Form
    ——————————————-

    End Of Form</span></div>

    // Example javascript watching code
    //—————————————
    function myPageInit(){
    // do my stuff after SPEasyForms
    }

    function stopWaitingForSPEF(){

    console.log(“stopWaitingForSPEF(): Clear setInterval myVar…”);
    clearInterval(myVar);
    }

    function startWaitingForSPEF(){

    console.log(“.ready(): startWaitingForSPEF(): setInterval myVar…”);

    myVar = setInterval(function(){

    if($(‘div[data-containername^=”Section Header End Of Form”]’).length > 0)
    {
    console.log(“.ready(): startWaitingForSPEF(): Found End Of Form SPEF!”);
    stopWaitingForSPEF();
    myPageInit();

    }
    else
    {
    console.log(“.ready(): startWaitingForSPEF(): Waiting for SPEF… “);
    }

    }, 2000);

    }

    //———————————————————————DR
    $(document).ready(function() {

    startWaitingForSPEF();

    }); // document.ready
    //———————————————————————-DR

    • This topic was modified 2 years, 5 months ago by hzynst.
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Scroll to top