Fixes #2053 Move script and add a user interaction

Now, to let the selectize plugin initialize, at onChange we check whether one of the inputs has been focused
This commit is contained in:
Willy "Linty
2023-12-05 14:44:38 +01:00
parent 85a6b11dec
commit d838ab3f17
2 changed files with 20 additions and 17 deletions

View File

@@ -32,6 +32,26 @@ $(document).ready(function () {
$(".related-categories-container .breadcrumb-item .remove-item").on("click", function () {
remove_related_category($(this).attr("id"));
})
// Unsaved settings message before leave this page
let form_unsaved = false;
let user_interacted = false;
$('#pictureModify').find(':input').on('focus', function () {
user_interacted = true;
});
$('#pictureModify').find(':input').on('change', function () {
if (user_interacted) {
form_unsaved = true;
console.log($(this)[0].name, $(this));
}
});
$(window).on('beforeunload', function () {
if (form_unsaved) {
return 'Somes changes are not registered';
}
});
$('#pictureModify').on('submit', function () {
form_unsaved = false;
});
})
function fill_results(cats) {

View File

@@ -90,23 +90,6 @@ $('#action-delete-picture').on('click', function() {
{/literal}
}());
{literal}
// Unsaved settings message before leave this page
$(document).ready(function() {
let form_unsaved = false;
$('#pictureModify').find(':input').on('change', function() {
form_unsaved = true;
});
$(window).on('beforeunload', function() {
if (form_unsaved) {
return 'Somes changes are not registered';
}
});
$('#pictureModify').on('submit', function() {
form_unsaved = false;
});
});
{/literal}
{/footer_script}
{combine_script id='picture_modify' load='footer' path='admin/themes/default/js/picture_modify.js'}