cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

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

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!

0 Kudos
Reply
3 Replies
Highlighted
Automation Master
Automation Master

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

is here any specific reason to trigger your function by submit button?

you can invoke your validation function from within validation rule. that way it will not interfere with submit event, and submit itself will be triggered just after your validation passes through

Reply
Not applicable

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

Your solution helped with most cases after tweaking the return value to be !confirm(...). Only thing is that when the user clicks Cancel, it takes the user back to the form, which is what we want, but it throws the invalid message highlighting the attachment control in red. We don't need to show that because it's an optional field. It works functionally but not as user-friendly we'd like it to be.

Reply
Automation Master
Automation Master

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

not to highlight attachment control you might try following

- add a custom class to the respective attachment control, eg. attctrl

- place following code into ready() or RegisterAfterReady() events

    NWF$('.attctrl').removeClass("nf-filler-highlightonvalidationerror");

this will preserve validation functionality on the control but will not highlight it when validation does not pass.

however, you will still get validation message at the top of the form.

it could be possible to remove this as well, but that would quite complicated since would need identify whether the attachment validation message is the only validation message or not, resp. identify somehow which validation message out of several ones belongs to your attachment validation.

I would rather suggest that you formulate that message to kind of warning/notification and let it display.

Reply