# Does typedInput save typed values?

**URL:** <https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972>\
**Category:** Developing Nodes\
**Created:** [30 December 2022 22:12 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972 "2022-12-30T22:12:31Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [30 December 2022 22:12 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/1 "2022-12-30T22:12:31Z")

</div>

I'm always confused about what typedInput saves into the node and wonder whether I'm doing something wrong or this is as-designed...

If I have a typedInput and select the number type or boolean type, will the node get a javascript Number respectively boolean or will it get a string with the number respectively a string with "true"/"false"?

I built a minimal test-case which suggests that the value saved is always a string and thus the node implementation has to make the conversion to the intended type. Is this correct or am I simply missing a trick?

typedinput-test.js:

```auto
module.exports = function(RED) {

  function typedinput_test(config) {
    RED.nodes.createNode(this, config)
    console.log("typedinput_test", JSON.stringify(config))
  }

  RED.nodes.registerType("typedinput test", typedinput_test)
}

```

typedinput-test.html:

```auto
<script type="text/javascript">
  RED.nodes.registerType('typedinput test', {
    category: "tests",
    color: "#FFFF00",
    defaults: {
      name: {value:""},
      test_string:{value:"default string", required:true},
      test_number:{value:125, required:true},
    },
    inputs: 0,
    outputs: 1,
    icon: "font-awesome/fa-th",
    paletteLabel: "typedinput test",

    label() { return this.name || "typedinput test" },

    oneditprepare() {
      console.log("oneditprepare", this)
      $("#node-input-test_string").typedInput({
        type:"str",
        types:["str","num","bool"],
        typeField: "#node-input-test_string-type"
      })
      $("#node-input-test_number").typedInput({
        type:"str",
        types:["str","num","bool"],
        typeField: "#node-input-test_number-type"
      })
    },
  });
</script>

<script type="text/html" data-template-name="typedinput test">
  <div class="form-row">
    <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
    <input type="text" id="node-input-name" placeholder="Name" />
  </div>
  <div class="form-row">
    <label for="node-input-test_string">Test string</label>
    <input type="text" id="node-input-test_string" />
    <input type="hidden" id="node-input-test_string-type" />
  </div>
  <div class="form-row">
    <label for="node-input-test_number">Test number</label>
    <input type="text" id="node-input-test_number" />
    <input type="hidden" id="node-input-test_number-type" />
  </div>
</script>

<script type="text/html" data-help-name="typedinput test"></script>

```

The edit panel comes up:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7dcdf93370874bb9ec79038a776d0d9a6ba699cf.png)

I change it:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/6/363e97e2dfb9c48d22d12b83142751de46ef068c.png)

I deploy and the node prints:

```auto
typedinput_test {"id":"f553feb13caf2a2d","type":"typedinput test","z":"451d9acba8e52c2f","name":"",
"test_string":"true","test_number":"44",
"x":680,"y":480,"wires":[[]]}                                                                           

```

And I see that both test\_string and test\_number have string values.

---

<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:** [30 December 2022 22:34 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/2 "2022-12-30T22:34:00Z")

</div>

Yes it should be remembered.

See this post: [Node Creation oneditprepare - #2 by Steve-Mcl](https://discourse.nodered.org/t/node-creation-oneditprepare/72840/2) and the solution 2 posts below.

In short, while the values might be saved as string, using the `RED.util` function knows how to restore the correct value and type selected by the user.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [30 December 2022 22:43 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/3 "2022-12-30T22:43:21Z")

</div>

It will only be remembered if you've added the appropriate property to your `defaults` object to store the type value in.

For your example code, that would be `test_string-type` and `test_number-type`

---

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [30 December 2022 23:03 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/4 "2022-12-30T23:03:06Z")

</div>

> [@knolleary](#):
>
> It will only be remembered if you've added the appropriate property to your `defaults` object to store the type value in.
> 
> For your example code, that would be `test_string-type` and `test_number-type`

Which piece of documentation did I miss?

So I changed the defaults to:

```auto
      test_string:{value:"default string", required:true},
      'test_string-type':{value:"str"},
      test_number:{value:125, required:true},
      'test_number-type':{value:"num"},

```

But the output from my node is still:

```auto
typedinput_test {... ,
  "test_string":"true","test_string-type":"bool",
  "test_number":"36","test_number-type":"num" ,...}                        

```

So this doesn't really solve the problem...

> [@Steve-Mcl](#):
>
> In short, while the values might be saved as string, using the `RED.util` function knows how to restore the correct value and type selected by the user.

Ok, so finally this does it:

```auto
  function typedinput_test(config) {
    RED.nodes.createNode(this, config)
    console.log("typedinput_test", JSON.stringify(config))
    console.log("Typed test_string:",
      RED.util.evaluateNodeProperty(config.test_string, config["test_string-type"], this))
    console.log("Typed test_number:",
      RED.util.evaluateNodeProperty(config.test_number, config["test_number-type"], this))
  }

```

produces

```auto
Typed test_string: true                                                          
Typed test_number: 34                                                            

```

🤔

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [30 December 2022 23:18 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/5 "2022-12-30T23:18:15Z")

</div>

> [@tve](#):
>
> Which piece of documentation did I miss?

This came up in another thread a couple days ago. I realise it is a bit of inferred information that needs to be made more explicit. It's on my list of doc updates I'm going to try to make in the coming days.

Likewise the info on evaluateNodeProperty.

---

<div class="post-metadata">

**Author:** ![kevinGodell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kevingodell/32/27040_2.png) [@kevinGodell](https://discourse.nodered.org/u/kevinGodell)\
**Post date:** [30 December 2022 23:29 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/6 "2022-12-30T23:29:16Z")

</div>

I don't intend to pile on, but the conversion to strings after saving values in the configuration menu cost me more time than writing the backend code. I eventually gave up on trying to figure out why my booleans and numbers arrived as strings on the backend, so I just started checking `if value !== 'false'` or using parseInt to get the values I needed on the backend and ran with it. Obviously, my lack of understanding was the problem, but man oh man, did I really try to get that boolean to arrive 😅

---

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [30 December 2022 23:52 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/7 "2022-12-30T23:52:19Z")

</div>

> [@kevinGodell](#):
>
> the conversion to strings after saving values in the configuration menu cost me more time than writing the backend code.

Oh, I cannot count the number of hours I've wasted on trying to get typedInput to work in a reasonable manner nor the number of hours trying to reverse engineer what it does and looking for the non-existant code that would make the types right. Anyone who thinks this design is nice or user friendly lives in a separate universe from mine...

---

<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:** [31 December 2022 10:06 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/8 "2022-12-31T10:06:37Z")

</div>

yes - we live in a universe where we think supportive comments offer much more encouragement for developers to write documentation.

---

<div class="post-metadata">

**Author:** ![kevinGodell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kevingodell/32/27040_2.png) [@kevinGodell](https://discourse.nodered.org/u/kevinGodell)\
**Post date:** [31 December 2022 14:53 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/9 "2022-12-31T14:53:39Z")

</div>

> [@dceejay](#):
>
> supportive comments offer much more encouragement

I just wanted you to know that I am very fond of you and the great work that you do 😍. If you ever see any thing that I post and you are unsure of my attitude, just know that I am either trying to be joky or maybe a little sarcastic. I have tried to include emoticons to help relay my feelings, but as my wife has told me many times, when I talk to people I sound like I want to fight 🤣. And to further extend how sensitive I have tried to be lately, I feel that I found a bug in the editor but not once did I use the word `bug` in my [recent post](https://discourse.nodered.org/t/is-a-flow-considered-to-be-dirty-modified-if-one-of-its-wires-is-cut/72732).

---

<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:** [31 December 2022 16:07 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/10 "2022-12-31T16:07:53Z")

</div>

Yes - 2022 has been a long long year. A lot has been accomplished, and a lot of progress made. On a project that is ever changing and growing there will always be parts that get overlooked or left behind, and bugs to be found 😉 - but it is often the same set of hands that ends up spinning all the plates. As long as we are all helping to pull in the same direction (which I think we are most of the the time) then I'm sure we will make everything better for everybody.

---

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [31 December 2022 16:13 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/11 "2022-12-31T16:13:00Z")

</div>

> [@dceejay](#):
>
> yes - we live in a universe where we think supportive comments offer much more encouragement for developers to write documentation.

I appreciate your comment and want to apologize for having vented. Sometimes calling a spade a spade also has its merits. Documentation would help. Revising the functionality might help more, though... (Moving away from jquery DOM hacking might help even more, but that argument is for another day.)  
At least I've contributed a possible complete end-to-end example for the docs above...

---

<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:** [31 December 2022 16:25 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/12 "2022-12-31T16:25:05Z")

</div>

NP - we all have to vent from time to time. As usual sometimes designs "evolve" and what started as a good idea doesn't really stand the bright light of hindsight. So yes alternatives can always be discussed, but need to be mindful of breakage and migration especially when it's such a core piece of functionality. And indeed docs like PRs too.

And thanks or all your efforts on flexdash - it feels like it's really starting to take shape.

---

<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:** [31 December 2022 17:57 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/13 "2022-12-31T17:57:15Z")

</div>

Glad to see we're all friends again 😇

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 January 2023 15:34 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/14 "2023-01-01T15:34:40Z")

</div>

I have added some docs on the handling of `typeField`: [TypedInput Widget : Node-RED](https://nodered.org/docs/api/ui/typedInput/#options-typeField)

And on how to parse the values in the runtime side: [TypedInput Widget : Node-RED](https://nodered.org/docs/api/ui/typedInput/#runtime-handling-of-typed-values)

---

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [1 January 2023 16:14 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/15 "2023-01-01T16:14:31Z")

</div>

> [@knolleary](#):
>
> I have added some docs

Niice!

Q: these two parts of the example don't fit together, right? (mismatch in element selectors)

```auto
$(".input").typedInput({
    typeField: ".my-type-field"
});

```

and

```auto
<div class="form-row">
    <label>Example:</label>
    <input type="text" id="node-input-myField">
    <input type="hidden" id="node-input-myFieldType">
</div>

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 January 2023 16:56 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/16 "2023-01-01T16:56:38Z")

</div>

The html goes with the more complete JavaScript example below it that shows it in the context of a node definition.

---

<div class="post-metadata">

**Author:** ![kevinGodell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kevingodell/32/27040_2.png) [@kevinGodell](https://discourse.nodered.org/u/kevinGodell)\
**Post date:** [2 January 2023 22:48 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/17 "2023-01-02T22:48:56Z")

</div>

from the updated docs:  
"Due to the way the `typedInput` enhances a regular HTML `<input>` , its value is stored as a string."

That line right there will save many new devs from trying to figure out why they are getting strings. Thank you.

---

<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:** [3 March 2023 22:48 UTC](https://discourse.nodered.org/t/does-typedinput-save-typed-values/72972/18 "2023-03-03T22:48:57Z")

</div>

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