【最新ニュース登録】ダイアログ重複表示修正
All checks were successful
Deploy main / deploy (push) Successful in 22s

This commit is contained in:
你的名字 2025-10-27 22:55:07 +09:00
parent 9855fc9b6d
commit 5b6b4faa14
2 changed files with 34 additions and 31 deletions

View File

@ -224,18 +224,6 @@
form.submit(); form.submit();
} }
if (window.jQuery && window.$ && $.confirm) {
$.confirm({
title: '確認ダイアログ。',
content: '登録してよろしいですか? はい/いいえ',
buttons: {
ok: { text: 'はい', btnClass: 'btn-primary', action: submitNow },
いいえ: function () {}
}
});
} else {
if (confirm('登録してよろしいですか?')) submitNow();
}
}); });
})(); })();
</script> </script>

View File

@ -159,17 +159,17 @@
<script> <script>
(function(){ (function(){
// 全選択 // 全選択チェックボックスの処理
document.getElementById('check-all')?.addEventListener('change', function(e){ document.getElementById('check-all')?.addEventListener('change', function(e){
document.querySelectorAll('input[name="ids[]"]').forEach(function(el){ el.checked = e.target.checked; }); document.querySelectorAll('input[name="ids[]"]').forEach(function(el){ el.checked = e.target.checked; });
}); });
// 共通: 未選択アラート // ▼ 共通:削除対象が未選択の場合のアラート表示
function showNoSelection(){ function showNoSelection(){
if (window.jQuery && window.$ && $.confirm) { if (window.jQuery && window.$ && $.confirm) {
$.confirm({ $.confirm({
title: '確認ダイアログ。', title: '確認ダイアログ。',
content: '削除対象が選択されていません。はい/いいえ', content: '削除対象が選択されていません。',
buttons: { buttons: {
ok: { text: 'はい', btnClass: 'btn-primary' }, ok: { text: 'はい', btnClass: 'btn-primary' },
いいえ: function () {} いいえ: function () {}
@ -180,12 +180,12 @@
} }
} }
// 共通: 削除確認ダイアログ // ▼ 共通:削除確認ダイアログ表示
function showDeleteConfirm(onYes){ function showDeleteConfirm(onYes){
if (window.jQuery && window.$ && $.confirm) { if (window.jQuery && window.$ && $.confirm) {
$.confirm({ $.confirm({
title: '削除ダイアログ', title: '削除確認',
content: '削除してよろしいですか?', content: '削除してよろしいですか?',
buttons: { buttons: {
ok: { text: 'はい', btnClass: 'btn-primary', action: function(){ if (typeof onYes==='function') onYes(); } }, ok: { text: 'はい', btnClass: 'btn-primary', action: function(){ if (typeof onYes==='function') onYes(); } },
いいえ: function () {} いいえ: function () {}
@ -196,9 +196,18 @@
} }
} }
// 削除ボタン(#delete_edit— 選択確認 → ダイアログ → 提出 // ▼ 削除ボタン(#delete_editのクリックイベント処理
document.getElementById('delete_edit')?.addEventListener('click', function(e){ // ①選択チェック → ②確認ダイアログ → ③削除フォーム送信
const delBtn = document.getElementById('delete_edit');
if (delBtn && delBtn.dataset.bound !== '1') {
delBtn.dataset.bound = '1'; // 二重バインド防止
// 捕捉段階で処理を実行し、他のリスナーによる重複ダイアログを防止
delBtn.addEventListener('click', function(e){
e.preventDefault(); e.preventDefault();
e.stopPropagation();
if (e.stopImmediatePropagation) e.stopImmediatePropagation();
const checked = document.querySelectorAll('input[name="ids[]"]:checked').length; const checked = document.querySelectorAll('input[name="ids[]"]:checked').length;
if (!checked) return showNoSelection(); if (!checked) return showNoSelection();
@ -206,14 +215,20 @@
if (!form) return; if (!form) return;
showDeleteConfirm(function(){ showDeleteConfirm(function(){
// jQuery 側の submit イベントを回避して、ネイティブでフォーム送信
form.submit(); form.submit();
}); });
}); }, true);
}
// フラッシュ自動閉じ // ▼ フラッシュメッセージ成功エラーを5秒後に自動で非表示化
setTimeout(function(){ setTimeout(function(){
document.querySelectorAll('.alert-dismissible')?.forEach(function(el){ el.classList.remove('show'); el.style.display='none'; }); document.querySelectorAll('.alert-dismissible')?.forEach(function(el){
el.classList.remove('show');
el.style.display='none';
});
}, 5000); }, 5000);
})(); })();
</script> </script>
@endsection @endsection