Prompting and Dirty Forms
Posted: 02 Dec 2018
I have an existing application that is built on Forms Designer 3.1.5
The users have requested the ability to prevent accidental loss of entered data
I have spoken with SPFORM support about this and there is discouraging news about the ability to do this, based on modern browsers, with pop-ups etc.
So before I proceed on the following detailed solution, I would like someone to weigh in on it's viability. I have tested this solution in Edge, IE, Chrome, and Firefox and all the results are the same and positive, even though it does not show the actual message, all the browsers ask me if I am sure I want to leave, this is whenever I have a Dirty form and either close the tab, browse away or click Cancel which is the desired result. This app would only ever be accessed by internal personnel who are inside the network and the Site is trusted as an Intranet site.
Please review this and give me any feedback, because to me it seems like it works fine and meets my goals. and please be gentle, I am not a Javascript programmer by any stretch of the imagination I am only pitching in which is why I would not put this in production without feedback.
Thank you
JavaScript Editor:
window.isNotSaved = true;
isDirty = false;
var msg = 'Not Saved';
$(document).ready(function(){
$(':input').change(function(){
if(!isDirty){
isDirty = true;
}
});
window.onbeforeunload = function(){
if((isDirty) && window.isNotSaved) {
return msg;
}
};
});
OnClick Event of Save Button:
window.isNotSaved = false;
The users have requested the ability to prevent accidental loss of entered data
I have spoken with SPFORM support about this and there is discouraging news about the ability to do this, based on modern browsers, with pop-ups etc.
So before I proceed on the following detailed solution, I would like someone to weigh in on it's viability. I have tested this solution in Edge, IE, Chrome, and Firefox and all the results are the same and positive, even though it does not show the actual message, all the browsers ask me if I am sure I want to leave, this is whenever I have a Dirty form and either close the tab, browse away or click Cancel which is the desired result. This app would only ever be accessed by internal personnel who are inside the network and the Site is trusted as an Intranet site.
Please review this and give me any feedback, because to me it seems like it works fine and meets my goals. and please be gentle, I am not a Javascript programmer by any stretch of the imagination I am only pitching in which is why I would not put this in production without feedback.
Thank you
JavaScript Editor:
window.isNotSaved = true;
isDirty = false;
var msg = 'Not Saved';
$(document).ready(function(){
$(':input').change(function(){
if(!isDirty){
isDirty = true;
}
});
window.onbeforeunload = function(){
if((isDirty) && window.isNotSaved) {
return msg;
}
};
});
OnClick Event of Save Button:
window.isNotSaved = false;