work around browser triggering onblur with remote form submissions (oof)

This commit is contained in:
drusepth 2023-01-30 18:36:58 -08:00
parent 7cc3b07087
commit bec2b4d52e

View File

@ -1,4 +1,6 @@
$(document).ready(function() {
var recent_autosave = false;
$('.autosave-closest-form-on-change').change(function () {
var content_form = $(this).closest('form');
@ -6,7 +8,10 @@ $(document).ready(function() {
if (content_form) {
// M.toast({ html: 'Saving changes...' });
console.log('saving changes');
content_form.submit();
recent_autosave = true;
content_form.trigger('submit');
setTimeout(() => recent_autosave = true, 1000);
} else {
console.log('error saving changes');
// M.toast({ html: "There was an error saving your changes. Please back up any changes and refresh the page." });
@ -23,6 +28,8 @@ $(document).ready(function() {
// To ensure all fields get unblurred (and therefore autosaved) upon navigation,
// we use this little ditty:
window.onbeforeunload = function(e){
$(document.activeElement).blur();
if (!recent_autosave) {
$(document.activeElement).blur();
}
}
});