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
Hi @SAI_JAGADEESH15,
this popup is from the widget called SC Order Guide:
https://yourinstance.service-now.com/nav_to.do?uri=sp_widget.do?sys_id=480ca054db03320064301150f0b8f545
But I don't recommend to modify this behaviour as it's OOTB, if you really need to, then still don't do it but if you need to do it anyways, first clone the widget and do the modifications in the cloned version.
Thank you for supporting my efforts by accepting this as solution
No AI was used in the writing of this post. Pure #GlideFather only
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @SAI_JAGADEESH15 - What do you mean by "restrict that"? What is your desired behavior?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @Sheldon Swift ,
Let say I filled the form but i changed my mind and selected on home page without saving,
Then we will get pop up,
So customers dont want this
I want only happen when page_id=pag_my_suyvey(Cloned widget)
Can you help me out with this please
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
function ($rootScope, $window, spModal, i18n, cabrillo) {
'use strict';
var registeredForms = {};
var isModalOpen = false;
var nativeMobile;
var previewMode = false;
function registerForm(form) {
registeredForms[form.getSysId()] = form;
}
function isNative(nativ) {
nativeMobile = nativ;
}
function isPreview(preview) {
previewMode = preview;
}
function unregisterForms(sysIds) {
sysIds.forEach(function (sysId) {
delete registeredForms[sysId];
});
}
function clearUserModifiedFields() {
var includedForms = Object.keys(registeredForms);
includedForms.forEach(function (includedForm) {
if (registeredForms[includedForm].isUserModified())
registeredForms[includedForm].$private.userState.clearModifiedFields();
});
}
function checkForDirtyForms() {
if (!g_dirty_form_warning_enabled || previewMode)
return false;
var isFormDirty = false;
var includedForms = Object.keys(registeredForms);
for (var i in includedForms) {
if (registeredForms[includedForms[i]].isUserModified()) {
isFormDirty = true;
break;
}
}
return isFormDirty;
}
function clearCabrilloButtons() {
if (cabrillo.isNative() && nativeMobile) {
cabrillo.viewLayout.setTitle('');
cabrillo.viewLayout.setNavigationBarButtons();
cabrillo.viewLayout.setBottomButtons();
}
}
$rootScope.$on('$locationChangeStart', function (event, next) {
if (!isModalOpen) {
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();
clearUserModifiedFields();
$window.location = next;
}
} else {
isModalOpen = true;
spModal.open(options).then(function (confirm) {
isModalOpen = false;
if (confirm.value == "leave") {
clearUserModifiedFields();
$window.location = next;
}
}, function () {
isModalOpen = false;
});
}
}
else {
clearCabrilloButtons();
}
} else {
event.preventDefault();
}
});
$rootScope.$on('$locationChangeSuccess', function () {
if (!g_persist_msgs_through_page_nav)
$rootScope.$broadcast('$$uiNotification.dismiss');
});
$window.onbeforeunload = function () {
if (checkForDirtyForms())
return true;
}
$window.onpagehide = function () {
clearCabrilloButtons();
}
return {
register: registerForm,
unregisterForms: unregisterForms,
isNative: isNative,
isPreview: isPreview
}
} An event listener is registered for the angularjs native event $locationChangeStart from here and the handler opens the modal. To override this behaviour you can just copy the above function into a widget angular provider, name it "spSCNavStateManager", link it to your widget and it will be used instead.
This of course won't create a skipped record in an upgrade as the original factory is not a platform artefact so it's good consider the governance aspects with the appropriate stakeholders.