AnsweredAssumed Answered

Is it possible to call a JavaScript function in the Confirmation Message on a Save/Submit button?

Question asked by eunyoungc on Aug 3, 2016
Latest reply on Aug 17, 2016 by emha

I'm trying to add a conditional confirmation message to the form.

 

The requirements are:

1. Attachments are optional.

2. On submit, required fields validation should happen without prompting the user about the attachment. -- The second part of this requirement (in italic) is a low priority and may be compromised.

3. If all required fields are filled out and no attachment is provided, on submit, prompt the user to confirm that they would like to submit the form without an attachment.

4. If OK, submit the form.

5. If Cancel, return to the form without submitting.

6. If attachment is provided at the time of submission, no prompt for confirmation is needed.

 

A couple things I've tried so far:

1. Set the button to Save and Submit and call a custom JavaScript function on Client Click.

function confirmAttachment()

{

    var attTable = document.getElementById(document.querySelector('[id^="idAttachmentsTable"]').id);

    var attRow = document.getElementById(document.querySelector('[id^="idAttachmentsRow"]').id);   

   

    // No attachments

    if (attTable != null && attTable.rows.length == 0)

    {

        return confirm("Would you like to submit this without a resignation letter?");

    }

}

>> The issue with this approach was that it submitted the form even when the user clicked Cancel on the confirmation message instead of taking the user back to the form.

 

2. Set the button to Save and Submit and add a Confirmation Message ("Would you like to....?") to the button.

>> The issues with this approach was that it prompts the user even when they provided attachment(s).

 

It seems to me that either 1) if I can call the JavaScript function above in the built-in Confirmation Message or 2) if I can trigger the standard Save and Submit process (including validation) in the JavaScript function when the confirmation returns true, it would solve the issues. Does any of this sound feasible? Or any other approach I should take? Thank you!

Outcomes