【最新ニュース登録】ダイアログ重複表示修正
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();
}
if (window.jQuery && window.$ && $.confirm) {
$.confirm({
title: '確認ダイアログ。',
content: '登録してよろしいですか? はい/いいえ',
buttons: {
ok: { text: 'はい', btnClass: 'btn-primary', action: submitNow },
いいえ: function () {}
}
});
} else {
if (confirm('登録してよろしいですか?')) submitNow();
}
});
})();
</script>

View File

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