I want to restrict the popup message when someone exits the form without submitting it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Here, when I fill in the form and then change my mind and exit without submitting it, an out-of-the-box popup appears.
Now I need to restrict that,
Kindly help me with the approach, Thanks in advance !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
why to remove that?
It's best to show that message to user as it's a warning to them.
keep that OOTB
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @Ankur Bawiskar
The client want to remove it,
only for custom where page_id= pag_my_survey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
check other response where approach is shared
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Assuming you have cloned the Surveys and Assessments widget with id take_assessment and/or in your html template you have the spAssessmentModel directive (<sp-assessment-model> somewhere in there) then the same functionality is in a factory called spAsmtDirtyFormManager instead.
Logic is the same as in the other reply I wrote. Create the factory and add it as an angular provider to your widget. The script for this one:
function($rootScope, $window, spModal, i18n, cabrillo) {
'use strict';
var registeredForms = {};
var nativeMobile;
var isModalOpen = false;
function registerForm(form) {
registeredForms[form.getSysId()] = form;
}
function isNative(native) {
nativeMobile = native;
}
function unregisterForms(sysIds) {
sysIds.forEach(function (sysId) {
delete registeredForms[sysId];
});
}
function checkForDirtyForms() {
var includedForms = Object.keys(registeredForms);
var isFormDirty = false;
for (var i in includedForms) {
var fieldNames = registeredForms[includedForms[i]].getFieldNames();
isFormDirty = fieldNames.some(function (fieldName) {
var field = registeredForms[includedForms[i]].getField(fieldName);
if ((typeof field.original_add_info !== 'undefined' && field.original_add_info !== field.add_info) || (field.type !== 'attachment' && field.originalValue !== field.value))
return true;
});
if (isFormDirty)
break;
}
return isFormDirty;
}
function clearCabrilloButtons() {
if (cabrillo.isNative() && nativeMobile) {
cabrillo.viewLayout.setTitle('');
cabrillo.viewLayout.setNavigationBarButtons();
cabrillo.viewLayout.setBottomButtons();
}
}
//remove/edit from here
$rootScope.$on('$locationChangeStart', function (event, next) {
if (Object.keys(registeredForms).length == 0)
return;
if (checkForDirtyForms()) {
event.preventDefault();
var options = {
title: i18n.getMessage("Leave page?"),
headerStyle: { border: 'none', 'padding-bottom': 0 },
footerStyle: { border: 'none', 'padding-top': 0 },
message: i18n.getMessage("Changes you made will be lost."),
buttons: [
{ label: i18n.getMessage("Cancel"), value: "cancel" },
{ label: i18n.getMessage("Leave"), primary: true, value: "leave" }
]
};
if (cabrillo.isNative() && nativeMobile) {
var title = i18n.format("{0} {1}", options.title, options.message);
if (confirm(title)) {
clearCabrilloButtons();
$window.location = next;
}
} else {
isModalOpen = true;
spModal.open(options).then(function (confirm) {
if (confirm.value == "leave") {
$window.location = next;
}
isModalOpen = false;
}, function () {
isModalOpen = false;
});
}
} else {
clearCabrilloButtons();
}
});
//remove/edit to here
$window.onbeforeunload = function () {
if (Object.keys(registeredForms).length != 0 && (checkForDirtyForms() && !isModalOpen))
return true;
}
$window.onpagehide = function () {
clearCabrilloButtons();
}
return {
register: registerForm,
unregisterForms: unregisterForms,
isNative: isNative
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
✅ METHOD 1:
Disable popup completely in Service Portal
Add this to a Widget Client Script or a Theme JS Includes file
window.onbeforeunload = function() {
return null; // disables the warning popup
};
✅ METHOD 2:
Disable only for a specific page
Go to:
Service Portal -- Pages -- Select your page -- JS Includes
Add:
window.onbeforeunload = null;