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

Closed
opened 2025-12-29 21:39:45 +01:00 by adam · 4 comments
Owner

Originally created by @TitouanBonamy on GitHub (Apr 22, 2025).

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

Originally created by @TitouanBonamy on GitHub (Apr 22, 2025). ### 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](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event) the below code in my local install, it worked fine : ```html <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](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event) for example) ### Database changes _No response_ ### External dependencies _No response_
adam added the type: featurestatus: needs ownerpending closurecomplexity: low labels 2025-12-29 21:39:45 +01:00
adam closed this issue 2025-12-29 21:39:45 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 23, 2025):

Can't say I see much value in this. There's a good reason browsers don't do this natively: It can get very annoying very quickly.

@jeremystretch commented on GitHub (Apr 23, 2025): Can't say I see much value in this. There's a good reason browsers don't do this natively: It can get very annoying very quickly.
Author
Owner

@sleepinggenius2 commented on GitHub (Apr 23, 2025):

Reliably determining when the current state of a form has diverged from its initial state is a hard problem, only compounded when you introduce things like dynamic form rendering through HTMX. We have another application we use today that just asks if you're sure that you want to cancel every time that you abandon a form, regardless of whether an actual change has been made or not, and it is incredibly infuriating, especially when it can't tell you what changed and you have to figure out whether you actually did something or not. If this does get implemented, I would vote for it being a user preference and it would need to be much more robust than the code snippet in the FR body. For example, the code snippet doesn't take into account if the field is required or not, or if it was changed, but has been restored to its initial value or a permutation of it (order in a multi-select should not matter), just prevents the input from being unloaded without any prompt, and does not include textarea or select elements. Especially while doing development, I find myself playing around with forms and abandoning them quite often, which would be extremely annoying with something like this.

@sleepinggenius2 commented on GitHub (Apr 23, 2025): Reliably determining when the current state of a form has diverged from its initial state is a hard problem, only compounded when you introduce things like dynamic form rendering through HTMX. We have another application we use today that just asks if you're sure that you want to cancel every time that you abandon a form, regardless of whether an actual change has been made or not, and it is incredibly infuriating, especially when it can't tell you what changed and you have to figure out whether you actually did something or not. If this does get implemented, I would vote for it being a user preference and it would need to be much more robust than the code snippet in the FR body. For example, the code snippet doesn't take into account if the field is required or not, or if it was changed, but has been restored to its initial value or a permutation of it (order in a multi-select should not matter), just prevents the input from being unloaded without any prompt, and does not include textarea or select elements. Especially while doing development, I find myself playing around with forms and abandoning them quite often, which would be extremely annoying with something like this.
Author
Owner

@github-actions[bot] commented on GitHub (Jul 23, 2025):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Jul 23, 2025): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/main/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Aug 23, 2025):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Aug 23, 2025): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11059