Task Post Button + addEventListener: Unable to abort posting of comments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2018 08:59 AM
I'm attempting to throw a warning message to the user whenever additional comments are submitted, confirming if the user means to post customer-visible data. This works if saving/updating the record via an onSubmit client script. Since the "post" button isn't affected by this, I'm attempting to use addEventListener on an onLoad script to accomplish the same thing.
function onLoad() {
var workNotesDiv = document.querySelector(".comment-box");
var buttons = workNotesDiv.querySelectorAll("button");
var postBtn;
for (var i = 0; i < buttons.length; i++) {
if (buttons[i].firstChild.nodeValue.includes("Post"))
postBtn = buttons[i];
}
if (postBtn) {
postBtn.addEventListener("click", checkCommentsAlert);
}
}
function checkCommentsAlert() {
if (!g_form.hasField('comments'))
return;
if (g_form.getValue('comments') != '') {
if (confirm('You are about to submit comments to this record that will be visible by customers.'))
return true;
else {
g_form.submitted = false;
g_form.getControl('comments').focus();
return false;
}
}
}
Everything works except that it doesn't abort the submission; even though it returns false, the value can't go anywhere and thus, the form submission goes through unaffected.
How can I fix this issue? Thanks in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2018 02:08 AM
Function inside addEventListener() doesn't return anything, so this way you probably won't be able to prevent posting.
Anyway, was anyone able to find a solution for this? It would help me a lot as well. 🙂