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:
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).
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
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.
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
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.