# \[Feedback Wanted\] TypedInput and node validation

**URL:** <https://discourse.nodered.org/t/feedback-wanted-typedinput-and-node-validation/90033>\
**Category:** Core Development\
**Tags:** editor\
**Created:** [7 August 2024 11:29 UTC](https://discourse.nodered.org/t/feedback-wanted-typedinput-and-node-validation/90033 "2024-08-07T11:29:58Z")\
**Posts on this page:** 3\
**Page:** 1

<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:** [7 August 2024 11:29 UTC](https://discourse.nodered.org/t/feedback-wanted-typedinput-and-node-validation/90033/1 "2024-08-07T11:29:58Z")

</div>

Hi all,

Foreword: the validation of node fields aims to prevent user errors directly at the source. An error field will be marked in red and a message can be given to the user which gives him the where and the why. These two elements are important because without validation, the user will deploy and only after this deployment receive an error that he may not understand.

As you know, TypedInput has its own validation system.

If I call for your feedback, it's because the validation of the node overrides the validation of TypedInput. Lets me explain with the example of a TypedInput field which is of the type `msg`. This field therefore has a validator (internal).

If the node does not have a validator for this field, the node will retrieve the result of the validation of TypedInput. Note that this result is only obtained if the DOM element exists!

However, if the node has a validator for this field, TypedInput will validate the input **but also** the node.

I think the solution would be that the node validation validates the TypedInput fields only when the node configuration is saved. Which means that when the editor is opened, it's the TypedInput validation that is used and when the node is saved, it's the node validation.

Little reminder: the validation of a node can be called for several cases not only when the editor is saved. Filling a field triggers node validation (simplifying the idea in the code).

The problem of this topic concerns only the case where the editor is opened (and saved). Therefore the TypedInput validation is **useless** because it's overwritten by the validation of the node.

Do you agree with this principle?

Thank you for your feedback.

PS: It's important to resolve the question because this double validation will pose problems in the future. This double validation has always existed but its effects have only been seen since v4 because errors have been fixed.

---

<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:** [11 August 2024 13:14 UTC](https://discourse.nodered.org/t/feedback-wanted-typedinput-and-node-validation/90033/2 "2024-08-11T13:14:03Z")

</div>

Related Issue:

> <https://github.com/node-red/node-red/issues/4848>
>
> \## Description
> 
> \*\*Reminder\*\*: when the edit box is built, for each property de…fined in \`node.defaults\` a change handler is attached (\`attachPropertyChangeHandler\`) to the corresponding input. This handler triggers the validation of all properties defined in \`node.defaults\`. The validator comes from \`node.defaults\`.
> 
> Consider the following example of a TypedInput:
> 
> \`\`\`html
> \<div class="form-row"\>
> \<label for="node-input-foo"\>\<i class="fa fa-tag"\>\</i\> Foo\</label\>
> \<input type="text" id="node-input-foo" /\>
> \<input type="hidden" id="node-input-fooType" /\>
> \</div\>
> \`\`\`
> 
> Built with the \`msg\` type which has an internal validator.
> \`\`\`js
> $("#node-input-foo").typedInput({
> typeField: "#node-input-fooType",
> types: "msg",
> });
> \`\`\`
> 
> \- Without validator defined in the node
> 
> \`\`\`js
> {
> defaults: {
> foo: { value: "" },
> }
> }
> \`\`\`
> 
> If the user completes a field, as mentioned in my reminder, my foo input will be validated with the node validator. Since it doesn't exist it will get the value from the TypedInput validator.
> If the user now completes the foo field, the TypedInput validator is triggered AND also the node validator. Which is equivalent to validating twice with the TypedInput validator.
> 
> Note: node validation will only work if the DOM element exists. e.g. if closing the edit box marks an error, refreshing the page will no longer mark the node as an error.
> 
> \- With validator defined in the node
> 
> \`\`\`js
> {
> defaults: {
> foo: { value: "", validate: RED.validators.typedInput("fooType") },
> }
> }
> \`\`\`
> 
> If I now have a validator in the node, whether the user completes my foo field or another will trigger two validations (TypedInput and the node) with the consequence that the node is stronger. If the TypedInput validation returns an error but the node validation does not, the field will not be in error.
> 
> \*\*Conclusion\*\*:
> The goal of this issue is to highlight that a double validation exists for TypedInput inputs and that we should agree on the role of each because currently for these inputs the TypedInput validator is not highlighted (because overwritten).
> 
> My suggestion would be that \`attachPropertyChangeHandler\` does not attach to TypedInput inputs so that two validators can be defined. The TypedInput validator when the user completes this field and the node validator for other cases (save node...). This allows each validator to do its job. Another interest is that the node passed in context to the node validator will contain the up-to-date values - this is useful if the validation depends on another property.
> 
> \*\*Clarification\*\*: this double validation problem has existed for a long time but its consequences have only existed recently:
> \- node validator uses TypedInput result (#4455)
> \- TypedInput mark the field in error (#4747) - this clearly implies that before TypedInput did not mark that fields
> 
> \## Related Links
> 
> \[Related conversation on the Forum\](https://discourse.nodered.org/t/feedback-wanted-typedinput-and-node-validation/90033).

---

<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:** [10 October 2024 13:14 UTC](https://discourse.nodered.org/t/feedback-wanted-typedinput-and-node-validation/90033/3 "2024-10-10T13:14:56Z")

</div>

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