Close Window on Submit Rule

Tying a close window option to the submit button for those occasions when your popping or opening a window or tab with script.

3 Likes

+1 vote here as well. I’d like to be able to “pop open” a tab / window and then close it after a “submit” button is pressed. Even adding this as an action to take after workflow is completed would be fine. Thanks!

I’ll post some JavaScript code below that will wait for the form to finish submitting and close the browser window/tab.

Step 1
Add a unique ID for the Form’s Submit Rule confirmation messages Source Code.

For example, I’ll be adding the ID form-submitted to be used in the JavaScript code later on.
<p id="form-submitted">Form successfully submitted.</p>

Step 2

Find the form’s component ID.

For example, in this example, the component is component_3. This will be used as well in the JavaScript code below.

Step 3

Add the following code to the JavaScript section of the page.

Ensure the first two lines match your case in Step 1 (form-submitted) and Step 2 (component_3).

var submitRuleConfirmationId = 'form-submitted';
var componentId = 'component_3';

var formFinished = false;
function checkIfFormFinishedSubmitting() {
    if(formFinished === false) {
        if ($('#'+submitRuleConfirmationId).length) {
            formFinished = true;
        }
       window.setTimeout(checkIfFormFinishedSubmitting, 100);
    } else {
        close(); 
    }
}
TB.render(componentId,function(data){
    data.ele.find('.af-form-submit:not(.ng-hide)').click(function(){
        checkIfFormFinishedSubmitting();
    });
});