# Node boolean property converted to string

**URL:** <https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133>\
**Category:** Developing Nodes\
**Tags:** dashboard-2\
**Created:** [13 November 2024 21:13 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133 "2024-11-13T21:13:43Z")\
**Posts on this page:** 15\
**Page:** 1

<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:** [13 November 2024 21:13 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/1 "2024-11-13T21:13:43Z")

</div>

Hi folks,

I was trying to solve [this](https://github.com/FlowFuse/node-red-dashboard/issues/1450) dashboard issue, but I am a bit confused.

1. The [ui-slider](https://github.com/FlowFuse/node-red-dashboard/blob/main/nodes/widgets/ui_slider.html#L31) node has a boolean property:

2. When we double-click the node, the `oneditprepare` is triggered where that boolean `true` is loaded as a string `"true"` in the html element:

3. When you click the "Done" button of the config screen, the `oneditsave` is triggered where the string `"true"` from the html element is converted back to a boolean `true` and stored in this node:

4. But when you double-click the node again, the value in the `oneditpreare` seems to have become a string `"true"` (although we have stored in the previous step a boolean `true`):

The switching between the boolean and string values results in the node becoming dirty, and the "Deploy" button becoming active.

Does anybody know why the stored boolean value becomes a string? I assume it is being stored as a string value, because the loading works fine the first time.

Thanks!!  
Bart

---

<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:** [13 November 2024 21:55 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/2 "2024-11-13T21:55:08Z")

</div>

Not really followed that closely but my suspicion is that the boolean is being added as an HTML element attribute? If so, attributes are always strings. So you need to convert it back.

---

<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:** [14 November 2024 05:35 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/3 "2024-11-14T05:35:26Z")

</div>

Yes Julian that is correct:

- when you put a value in a hrml element of your config screen, then you need to convert it from a boolean to a string (in oneditprepare).
- when you get the value afterwards from the htmk element, then you need to convert it from a string to a boolean again (in oneditsave).

Both have been implemented correctly by Joe.

But the _ **problem** _ is: he saves a boolean into his node (in oneditsave) and afterwards (in oneditprepare) it is a string again.

Or is that standard behaviour? Too long ago. Don't remember anymore what is best way to deal with this...

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [14 November 2024 05:52 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/4 "2024-11-14T05:52:16Z")

</div>

I think, (not tried) the converting should be removed from editor and the actual usage of that property in vue should be made by using computed value. But may introduce breaking change...

---

<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:** [14 November 2024 06:19 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/5 "2024-11-14T06:19:01Z")

</div>

Morning @hotNipi,  
It is from the [config](https://github.com/FlowFuse/node-red-dashboard/blob/main/nodes/widgets/ui_slider.html#L31) screen, not the vue file. So the computed fields are not applicable to this issue. Too long ago that I wrote this kind of code, so a bit confused what is the best practice. My knowledge seems to be fading away...

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [14 November 2024 06:28 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/6 "2024-11-14T06:28:05Z")

</div>

I'll try once more...  
The usage of that property is in vue. The type of the property should be even string ('always') or boolean.  
The converting in config is unnecessary if the property usage will be via computed value.  
Let the it be string ("always", "true", "false") and use computed value in vue where you then convert "true" or "false" to actual boolean.

---

<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:** [14 November 2024 06:42 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/7 "2024-11-14T06:42:45Z")

</div>

Ok, thanks. Seems my brain is not fully awake yet. That makes sense yet.

But would like to understand what is wrong with Joe's code, because I don't see it. The default value is a boolean, and that arrives as a boolean in the oneditprepare. But afterwards it can never be a boolean again, only a string boolean? Was that normal behaviour of node properties? Joe is using boolean node properties all over the place, so I don't understand why this one causes an issue for some user.

---

<div class="post-metadata">

**Author:** ![hotNipi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hotnipi/32/383_2.png) [@hotNipi](https://discourse.nodered.org/u/hotNipi)\
**Post date:** [14 November 2024 06:49 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/8 "2024-11-14T06:49:33Z")

</div>

I think Joe was trying also to avoid breaking changes. Previous iteration had checkbox to even show or hide. The input element is now select and for that the handling is different thus the property needed to be converted. But as we know now, the converting in config has that nasty side-effect.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [14 November 2024 07:32 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/9 "2024-11-14T07:32:28Z")

</div>

String because select input. Outside of checkboxes (boolean), the value saved by the node (without oneditsave) is a string.

`oneditsave` has its own change mechanism, just like the internal editor save.

When `oneditsave` is called, it will transform the string into boolean - a change is detected.

When the internal editor save is called, the value previously changed to boolean will be changed back to string - here too the node detects a change.

That's why the `oneditsave` fails because the value is overwritten by the internal editor mechanism. So the value exported is always a string.

---

<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:** [14 November 2024 11:48 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/10 "2024-11-14T11:48:02Z")

</div>

Ok thank you all for illuminating me!  
Will try to fix that dashboard issue as soon as I find time.  
Have a nice day!

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [14 November 2024 11:55 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/11 "2024-11-14T11:55:51Z")

</div>

You'll have to check with Joe if the code in `oneditsave` is necessary. I assume it was a migration initially.

---

<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:** [3 December 2024 21:47 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/12 "2024-12-03T21:47:18Z")

</div>

@GogoVega (or other users of course...),

I have been doing a series of other PR's, but this one has lost my attention meanwhile. So I created a simple node to refresh my knowledge:

```auto
<script type="text/javascript">
    RED.nodes.registerType('test-data-conversions',{
        category: 'function',
        color: '#a6bbcf',
        defaults: {
            someString: {value: "initial"},
            someBool: {value: true},
            someInt: {value: 5}
        },
        inputs: 1,
        outputs: 1,
        icon: "file.svg",
        label: function() {
            return this.name||"lower-case";
        },
        oneditprepare: function() {
            debugger
        },
        oneditsave: function() {
            debugger
        }
    });
</script>

<script type="text/html" data-template-name="test-data-conversions">
    <div class="form-row">
        <input type="text" id="node-input-someString">
    </div>
    <div class="form-row">
        <input type="number" id="node-input-someInt">
    </div>
    <div class="form-row">
        <input type="checkbox" id="node-input-someBool">
    </div>
</script>

<script type="text/html" data-help-name="test-data-conversions">
    <p>A simple node to test data conversions</p>
</script>

```

The _ **first time** _ I arrive in the `oneditprepare` I get these values:

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

So the properties in `this` are simply the default values (with the correct types), assigned by the flow editor to my new node. But I had expected value `"false"` instead of `"on"`....

The _ **second time** _ I arrive in the `oneditprepare` I get these values:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75895bca02845a11457a175d7ddf9be356fe851c.png)

So the boolean is still a boolean, and the number is still a number. Which means not everything is converted by the flow editor to string values?

Somehow I am completely confused. Too long ago that I used this stuff 🤯  
I would really appreciate if you could illuminate my old brain...

---

<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:** [3 December 2024 22:43 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/13 "2024-12-03T22:43:15Z")

</div>

> [@BartButenaers](#):
>
> But I had expected value `"false"` instead of `"on"`.

Use `$(....).is(':checked')` for checkbox

> [@BartButenaers](#):
>
> The _ **second time** _ I arrive in the `oneditprepare` I get these values

Try changing values (check on -\> off, 5 -\> 6, "initial" -\> "changed"), press done then re-open & see values in oneditprepare once 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:** [4 December 2024 21:49 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/14 "2024-12-04T21:49:25Z")

</div>

OMG @Steve-Mcl, done that thousands of times and completely forgotten...  
Thanks for refreshing my brain!!

For those ever having the same question:

The _ **first time** _ I double click the node, I arrive in the `oneditprepare` with these values:

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

So the properties in `this` are simply the default values (with the correct types), assigned by the flow editor to my new node.

I change all 3 html input fields, and press the _"Done"_ button.  
In the `oneditsave` the `this` properties still contains the original values, but the html input elements contain the new updated values:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0bda360ccb7fb6100bea474fc877be2258136882.png)

After this function, the flow editor automatically converts everything (except booleans) to string values.

The _ **second time** _ I double click the node, I arrive in the `oneditprepare` with these values:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe7c87c912bec36e310eb2e32f54d79d90200b8a.png)

All the property values have become strings, except for booleans.

---

<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:** [18 December 2024 21:49 UTC](https://discourse.nodered.org/t/node-boolean-property-converted-to-string/93133/15 "2024-12-18T21:49:39Z")

</div>

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