# Upgrading Nodes specifically my own

**URL:** https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641
**Category:** Developing Nodes
**Created:** [28 August 2018 17:42 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641 "2018-08-28T17:42:39Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [28 August 2018 17:42 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/1 "2018-08-28T17:42:39Z")

</div>

I wonder if someone can advise. I've just made an update recently to node-red-contrib-bigtimer. While it works well (some new fields) - existing users will get the warning they need to fill in a value for the new fields. I figured as these are inputs, if I put a value "0" in there, existing users of the node would not be harrassed by this but I was wrong..

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [28 August 2018 18:01 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/2 "2018-08-28T18:01:20Z")

</div>

hard to guess on so little info but maybe it depends how you are testing - as "", 0 , false and undefined can all evaluate falsey in Javascript.

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [28 August 2018 18:23 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/3 "2018-08-28T18:23:00Z")

</div>

So I added

```auto
input="0"

```

to the new fields and STILL the existing node users (i.e. me) when upgrading the node, get faced with a warning that they need to complete entering info into the node. The node shows greyed out "0" without the quotes in the new fields but the user still has to put something in there manually - usually 0. I'd have thought me presetting an input value would prevent that.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [28 August 2018 18:51 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/4 "2018-08-28T18:51:24Z")

</div>

depends how you are triggering the warning.

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [28 August 2018 18:54 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/5 "2018-08-28T18:54:29Z")

</div>

So, the user updates the node Bigtimer and a red triangle appears next to the node which means they now need to fill in the zeros for the fields I've added which are supposed to default to value zero. Not a game changer but for example I have dozens of BigTimers in my installation.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [28 August 2018 19:02 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/6 "2018-08-28T19:02:23Z")

</div>

Just because the node has the new field doesn't mean the users old flow has it... so the validator will fail. (hence red triangle) - so you probably need to create a custom validator that accepts "nothing" or a number - and then in the js code treat nothing as 0. (assuming you really need to validate it)

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [29 August 2018 11:49 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/7 "2018-08-29T11:49:19Z")

</div>

I hate to admit this but after spending 2 hours on this, I could not come up with a working solution so I simply took the validators out.

Pete

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [29 August 2018 18:40 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/8 "2018-08-29T18:40:28Z")

</div>

The bit I really don't follow is... in the html form, you can enter value="0"... hich SHOULD put a default value of 0 in the input but cleraly doesn't.

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [29 August 2018 19:14 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/9 "2018-08-29T19:14:37Z")

</div>

I think you have to add that to the "default" section of the .js file, if you want that behavior, don't you?

---

<div class="post-metadata">

### Author: ![ncherry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ncherry/32/27_2.png) [@ncherry](https://discourse.nodered.org/u/ncherry)
#### Post date: [29 August 2018 19:42 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/10 "2018-08-29T19:42:34Z")

</div>

Hi Pete, I think I ran into something similar. One of the things I did was to change the field debug and received "... workspace contains some nodes that are not properly configured ... ". I had changed debug from a text input to a checkbox. The JSON for the flow still contained the "debug": "0" I had originally set it to (text field was a quick hack). Now I have it set as: to ndebug: { value: false } and left the original debug field in place but unused. I no longer see the complaint. This is not a proper solution but another hack until I can learn more.

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [29 August 2018 19:54 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/11 "2018-08-29T19:54:34Z")

</div>

Hi Pete,

Seems I'm a bit too late to avoid you suffering from a programming burn-out 😉  
But here is how I try to add new properties to my contributions. Don't know if it is a correct design, but it seemed to be working fine ...

- A new input field is added to an existing node:

- To make sure it is stored (and communicated to the server-side), I add a newProperty with a default value 123 and a number validator:

- To get rid of the red triangle, you can apply a custom number validator:

- Another issue at this moment is that ( at the server-side ) the property also doesn't exist yet:

- As soon as the user opens the config screen of the node, you will see in the _oneditprepare_ that the _newProperty_ doesn't exist here yet (for existing nodes in your flow):

Hopefully this explains some things to you, and hopefully I didn't make things explode in your brain 😉  
Bart

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [29 August 2018 20:01 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/12 "2018-08-29T20:01:54Z")

</div>

In the html file I have values in the javascript area and 0 shows up in the input field but not defaulting to 0 if you already gave the node and get the update.

xw5: {value:0},

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [29 August 2018 20:18 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/13 "2018-08-29T20:18:35Z")

</div>

I was under the impression that those defaults are for the UI (property edit panel).  
What happens if you also set a default inside the node's .js registration code? For example:

```auto
node.xw5 = n.xw5 || 0;

```

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [29 August 2018 20:38 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/14 "2018-08-29T20:38:06Z")

</div>

the default only applies to new nodes when you drag them on. Existing nodes are already there and the new property is missing so you need to do as Bart suggests for the validator eg something like

```
validate:function(v) { return ((v === "") || (RED.validators.number(v)) }

```

and also as he suggests to add it to the oneditprepare to default it fully.

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [29 August 2018 20:53 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/15 "2018-08-29T20:53:38Z")

</div>

What’s a oneditprepare?

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [29 August 2018 20:54 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/16 "2018-08-29T20:54:41Z")

</div>

I’ll try that thanks…

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [29 August 2018 20:56 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/17 "2018-08-29T20:56:06Z")

</div>

I’m with you except for the oneeditprepare – no idea what that is…

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [29 August 2018 20:56 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/18 "2018-08-29T20:56:36Z")

</div>

Pete,  
**oneditprepare** is a function that is being called as soon as you double click on your node (and your popup config screen dialog is being build). See [documentation](https://nodered.org/docs/creating-nodes/node-html). In that function you can do all kind of initialization. E.g. make sure that defaults are loaded for existing nodes that don't have the new property yet ...

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [29 August 2018 21:01 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/19 "2018-08-29T21:01:50Z")

</div>

You can register oneditprepare when you register your node. Something like this:

```auto
    RED.nodes.registerType('Blockly',{
        category: 'function',
        color: '#FFAAAA',       
        defaults: {
            newProperty: { value:123, validate: function(v) { debugger;
                                                               return !v || !isNaN(v); } },
            name: {value:""}
        },
        inputs:1,
        outputs:1,
        icon: "puzzle.png",
        label: function() {
            return this.name||"Blockly";
        },
        oneditprepare: function() {
            // Do some initialization stuff when the user double clicks on the node, just before the config screen is displayed
        },
        oneditsave: function() {
            // Do some stuff when the user presses the 'Done' button
        },
        oneditcancel: function() {
            // Do some stuff when the user presses the 'Cancel' button
        });
</script>

```

---

<div class="post-metadata">

### Author: ![scargill](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scargill/32/1118_2.png) [@scargill](https://discourse.nodered.org/u/scargill)
#### Post date: [30 August 2018 08:20 UTC](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641/20 "2018-08-30T08:20:14Z")

</div>

Ah, I do have one of those, I was looking in the wrong place, did that ages ago. Thanks for that.

[Next page](https://discourse.nodered.org/t/upgrading-nodes-specifically-my-own/2641.md?page=2)
