Skip to content

Add a warning pop-up to warn unsaved changes in form #19254

@TitouanBonamy

Description

@TitouanBonamy

NetBox version

V4.2.1

Feature type

New functionality

Proposed functionality

Add some Javascript to netbox in order to activate a pop-up that appear when leaving a form with unsaved data to warn the user.

I already tested based on the developer.mozilla documentation the below code in my local install, it worked fine :

<form action="" method="post" enctype="multipart/form-data" class="object-edit mt-5">
    <script type="text/javascript">
        const beforeUnloadHandler = (event) => {
            // Recommended
            event.preventDefault();

            // Included for legacy support, e.g. Chrome/Edge < 119
            event.returnValue = true;
        };

        document.addEventListener("input", (event) => {
            if (event.target.value !== "") {
                window.addEventListener("beforeunload", beforeUnloadHandler);
            } else {
                window.removeEventListener("beforeunload", beforeUnloadHandler);
            }
        });
    </script>

Use case

  1. A user is filling a form in NetBox (Site, Device, etc...)
  2. The user wants to leave the page but forgot to submit the form
  3. A pop-up show to remind him that the page has unsaved changes (see the beforeunload documentation for example)

Database changes

No response

External dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity: lowRequires minimal effort to implementpending closureRequires immediate attention to avoid being closed for inactivitystatus: needs ownerThis issue is tentatively accepted pending a volunteer committed to its implementationtype: featureIntroduction of new functionality to the application

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions