Skip to content

フォーム変更フラグの管理 #14

@aragig

Description

@aragig
		//--- 編集内容がある場合にブラウザバック防止
		let isFormDirty = false;
		// ページ離脱前に警告
		window.addEventListener("beforeunload", function (e) {
			if (isFormDirty) {
				e.preventDefault();
				e.returnValue = ""; // Chrome 用
			}
		});

		// 入力フォームに変化があれば dirty フラグを立てる
		document.querySelectorAll("#nuForm input, #nuForm textarea, #nuForm select").forEach(el => {
			el.addEventListener("change", () => {
				isFormDirty = true;
			});
			el.addEventListener("input", () => {
				isFormDirty = true;
			});
		});

ここら辺の監視をモジュール化する
→nu.dirty(function() {})
→nu.dirty.clear();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions