# How can I block closing the form panel unless the user clicked on Done,Cancel or Delete buttons?

**URL:** <https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675>\
**Category:** Developing Nodes\
**Created:** [21 April 2025 11:24 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675 "2025-04-21T11:24:49Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![AllanOricil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allanoricil/32/106911_2.png) [@AllanOricil](https://discourse.nodered.org/u/AllanOricil)\
**Post date:** [21 April 2025 11:24 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/1 "2025-04-21T11:24:49Z")

</div>

I need a reliable solution that doesn’t allow closing the node form when there are errors. At the moment I was able to partially accomplish this disabling the “Done” button. However, this solution doesn’t fully work because the form closes whenever the User clicks outside of it and the changes are applied to the node, even with errors.

These node changes must not be saved in the client if there are errors. If the User attempts to save his changes to the node form, I want to run my custom validation (which is based on json schema) and block the client updates if the validation returns erros. This has to work even if the User uses shortcuts.

 ![image-1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/d/cd9e77a4af62fcec6c5fe1ec0930e877fa12e624.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 April 2025 11:39 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/2 "2025-04-21T11:39:33Z")

</div>

The current UX is as follows.

1. User closes the edit form (however that occurs)
2. If there are errors, a badge is applied to the node
3. If the user attempts to deploy, they are made aware of node configuration errors.
4. User can simply open the "bad node" and fix it.

![chrome_C3uXl2Spn0](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fd39e0c1eed8747d66e9627c40ef05df4d1821a6.gif)

Applying any workarounds or hacks to prevent the current standard operation will likely not age well (if/when the editor logic is changed in the core)

* * *

EDIT:

I am not saying we couldn't / shouldn't have a means of preventing form dismissal just that there is not currently a standard means of doing so.

If you have a concrete proposal, please do make it & we can all evaluate.

That might be adding a new hook - something like `onclose` to the API e,g...

```auto
definition.onclose = function(reason) {
    if (reason === 'cancel') {
        return true // user is cancelling, just let it close.
    }
    return isValid() // if `isValid` returns true, form will close, if it returns false, form will remain open
};

```

---

<div class="post-metadata">

**Author:** ![AllanOricil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allanoricil/32/106911_2.png) [@AllanOricil](https://discourse.nodered.org/u/AllanOricil)\
**Post date:** [21 April 2025 11:56 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/3 "2025-04-21T11:56:37Z")

</div>

I liked the onclose. It wont cause any issues with the current ux and it is up to node authors to adopt.

---

<div class="post-metadata">

**Author:** ![AllanOricil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allanoricil/32/106911_2.png) [@AllanOricil](https://discourse.nodered.org/u/AllanOricil)\
**Post date:** [21 April 2025 12:04 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/4 "2025-04-21T12:04:44Z")

</div>

I would use it like this

// EDITED

```js
definition.oneditclose = function(reason) {
    if (reason === 'done') {
        return isValid()
    }
    return true
};

```

@Steve-Mcl the name of the new hook would have to be "oneditclose" to follow the naming conventions

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 April 2025 12:16 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/5 "2025-04-21T12:16:48Z")

</div>

Equally valid.

But it is just an opening proposal. Lets see if there are any comments good/bad/for/against

It may be that someone comes along and says:

"we cant do this because of abc"  
_or_  
"we shouldnt do this because of xyz"  
_or_  
"The function signature should also contain a parameter that is an array of property names and changes so I can evaluate if I 'care'"  
_or_  
"the return value should be an extensible `object` (for future proofing) with at minimum, `{"cancel": true, "reason": "Validation failed for field A"}` so that core can display a toast with a reason string for why closure was inhibited"  
_or_  
etc...

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 April 2025 12:26 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/6 "2025-04-21T12:26:46Z")

</div>

You may want to take a look at uibuilder's main node. On the file edit tab, it does disable the done button if an unsaved edit is outstanding. The node also turns off most settings until the "url" entry has been actually deployed.

---

<div class="post-metadata">

**Author:** ![AllanOricil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allanoricil/32/106911_2.png) [@AllanOricil](https://discourse.nodered.org/u/AllanOricil)\
**Post date:** [21 April 2025 12:29 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/7 "2025-04-21T12:29:32Z")

</div>

The reason I need this feature is because my node forms are highly complex to use `defaults.[prop].validate` for validations, and jquery to control form states. I'm building my forms using Vue and the validations are done with Json schema.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 April 2025 12:34 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/8 "2025-04-21T12:34:23Z")

</div>

Thats fine too. Just use a custom validator function on your defaults props.

> **[Node properties : Node-RED](https://nodered.org/docs/creating-nodes/properties#property-validation)**

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [21 April 2025 13:22 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/9 "2025-04-21T13:22:55Z")

</div>

Honestly this sounds like a good way to brick your node red. Want to copy something from _inside_ node red to another field (e.g. user name & password), start with user name, then want go back and add password. But when you want to copy the password, well the panel just won't disappear because now (after entering the user name) the password field is mandatory. So the form is in error.

Well what now? Delete the username or enter a fake password to get rid of the panel.

Definitely not a fan of the proposal. Just a nightmare waiting to jump out of the corner and bite the user ....

---

<div class="post-metadata">

**Author:** ![AllanOricil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allanoricil/32/106911_2.png) [@AllanOricil](https://discourse.nodered.org/u/AllanOricil)\
**Post date:** [21 April 2025 13:31 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/10 "2025-04-21T13:31:26Z")

</div>

> [@gregorius](#):
>
> Honestly this sounds like a good way to brick your node red. Want to copy something from _inside_ node red to another field (e.g. user name & password), start with user name, then want go back and add password. But when you want to copy the password, well the panel just won't disappear because now (after entering the user name) the password field is mandatory. So the form is in error.
> 
> Well what now? Delete the username or enter a fake password to get rid of the panel.

If you want to copy something from within node-red while your form is open, you can just open node-red in another tab and copy the things you need.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/674895352f3a932faaceab8415b3f20a736f7944.png)

---

<div class="post-metadata">

**Author:** ![AllanOricil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allanoricil/32/106911_2.png) [@AllanOricil](https://discourse.nodered.org/u/AllanOricil)\
**Post date:** [21 April 2025 13:37 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/11 "2025-04-21T13:37:42Z")

</div>

I found a solution that won't let the node form dialog close if there are errors.

```js
disableCommitChanges() {
          if (Object.keys(this.errors).length) {
            $("#node-dialog-ok").prop("disabled", true).addClass("disabled");
            $("#red-ui-workspace").css("pointer-events", "none");
          } else {
            $("#node-dialog-ok")
              .prop("disabled", false)
              .removeClass("disabled");
            $("#red-ui-workspace").css("pointer-events", "");
          }
},

```

EDIT:  
It is working as I expected! This shortcut isn't working when there are errors  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab2753a14257c6bf2d73f3a4c0efb3ce9c312177.png)

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [21 April 2025 13:54 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/12 "2025-04-21T13:54:50Z")

</div>

> [@AllanOricil](#):
>
> If you want to copy something from within node-red while your form is open, you can just open node-red in another tab and copy the things you need.

Very convenient. But hey it was the user that made the mistake of entering the wrong data in the first place, let them suffer the inconvenience.

I also don't like this idea because there is no point to it.

If there an error in the form, then as @Steve-Mcl pointed out, there is a visual cue on the flow. And that's about all that changed. No flow was deployed, no change made to the server, nothing breaks. The flow was not changed on the server.

Until the deploy button is pressed _nothing bad_ will happen. And if the user does press the deploy button, they get a warning and need to confirm that deploy. So to all those levels of "danger, will robertson, danger", the idea here to so add another layer of confusion. "Hey where's the done button gone to ... ah ok, there's an error on the form". A definite dark pattern in UI design.

For seasoned users this is a major inconvenience, for new users simply more confusion.

And for what? For pedantically telling the user they are stupid and are now being punished for entering the wrong data.

---

<div class="post-metadata">

**Author:** ![AllanOricil](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allanoricil/32/106911_2.png) [@AllanOricil](https://discourse.nodered.org/u/AllanOricil)\
**Post date:** [21 April 2025 14:01 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/13 "2025-04-21T14:01:13Z")

</div>

> [@gregorius](#):
>
> Very convenient. But hey it was the user that made the mistake of entering the wrong data in the first place, let them suffer the inconvenience.

How can the User to enter the wrong data if validations will still run as usual? Can you explain how this will happen with reproduction steps list? I'm not seeing it because the only change in the current behavior is that the node author can choose if he will or not allow the node form to close if there are errors.

If you install a node that has the new hook, and you don't like the behavior, you can fork the node's source code, if available, and remove the hook from its code.

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [21 April 2025 14:35 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/14 "2025-04-21T14:35:54Z")

</div>

> [@AllanOricil](#):
>
> How can the User to enter the wrong data if validations will still run as usual?

Ok the user enters data in some field with validation and the validations says the data is wrong. The warning lights gone on and the button is gone/deactivated. How does the user close panel?

What I am I missing here?

Of course the validations are running. How can I as a user close the panel to _find the right_ data? I can't. I'm stuck. So I delete the data again. But the field isn't allowed to be empty (hypothetically speaking). What now?

A field is not allowed to be empty, but I as user have no idea what goes into the field. I just opened a edit panel for a node. And immediately it's in error because some field can't be empty. Check the complete node for an example. It's in error when I pull it into the flow. Now I open the edit panel and have no idea what the complete node actually does. Now I can't close the panel because I want to read the help documentation on the complete node. No go. Too bad user, you screwed up, you should have read the documentation _before_ opening the edit panel. Curiosity and cats, a dangerous mix.

(Btw the complete node is the third from the top in a default installation of NodeRED - there is a likelihood that a new user encounters the red-triangle of error before anything else because of the complete node is third from top.)

Now instead I could create an endless loop either using the [status node](https://discourse.nodered.org/t/complete-split-is-the-value-wrong/96650/11) or the [complete node](https://discourse.nodered.org/t/complete-node-doesnt-check-for-recursion/96647) and nothing, absolutely nothing prevents me from doing that. All done buttons are there, no deploy warnings but my node red server melts.

Well that's nice. At least the done button is still there so that I can fix the problem ... hm what problem? Nothing in NodeRED is actually telling me what the problem _is_.

A far more interesting problem to solve is graph theory and to find potential endless loops within Node-RED flows. Now that would be something for which I would deactivate the _deploy_ button! _Hey User, you've just created a potential end less loop that might create molten metal of your NodeRED server, do you really want to deploy? If you do decide to deploy, here are the instructions of how to enter safe mode ...._.

But we'll deactivate the done button instead because a name field can't be empty (hypothetically speaking).

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [22 April 2025 08:33 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/15 "2025-04-22T08:33:04Z")

</div>

I think I'm inclined to agree with @gregorius, this could lead to a very frustrating user experience. There are already several mechanisms in place to warn of the incorrect configuration.

If the user insists on deploying, then the node should should just fail graciously, with a helpful warning.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [21 June 2025 08:33 UTC](https://discourse.nodered.org/t/how-can-i-block-closing-the-form-panel-unless-the-user-clicked-on-done-cancel-or-delete-buttons/96675/16 "2025-06-21T08:33:46Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
