Would you mind explaining a little about what's actually going on here (and what the result looks like)?
I'm not really clear what you are doing in the validator, or with the hidden field.
I also just baked this together from existing nodes, so hopefully I do not write garbage. In this case, one of the Node-RED creators has to correct me.
So basically there is an input field <input type="text" id="node-input-changeValue"> with id node-input-changeValue. This is where the actual value is typed into. However, if you want to use the built in editor widget for changing the type, you add this <input type="hidden" id="node-input-changeValueType"> field to it, which will create the dropdown and also for example the json editor etc.
In order to enable the functionality, you need the typeInput method, which is invoked when the node property editor is opened (oneditprepare). default: 'bool' says that the default type is a boolean, I also added changeValueType: { value: 'bool' }, although I am not certain if this is necessary (seems a bit redundant). The property typeField: $("#node-input-changeValueType") specifies the id of the hidden input. The types property allows you to state which types are available to choose from. There are more available, look for example in the inject node src.
The result will look like in the inject node, where you can select a type of property you want the user to type into your input field. If you choose json for example, then additionally there will be a button which allows you to open the json editor.
validate: RED.validators.typedInput('changeValueType') is a validator that checks if the typed in value is of valid selected type.
Finally, what you type in will be availbale in the changeValue property, represented as a string. To convert it to the type you have selected, there is the util function RED.util.evaluateNodeProperty(node.config.changeValue, node.config.changeValueType, node);
Hope that helps.
If you have additonal questions, please ask, but probably Nick has to answer them
Hi there, so when i select "msg" as desired type then i have to insert an if of switch in the "node.on" method so i set the msg.payload to the desired value of property? Or is there a simpler way?
Pretty late here but I just ran up against the exact same problem and figured it out. You need to create a default for the "type" field as well as the value field in your defaults defined in the html file. So in @cinhcet 's example above it's this bit that's important:
My problem was I had the changeValue field but not the changeValueType field so the type was never saving. It's also not very clear from the documentation that this is necessary although it seems obvious after I figured this out. Hope this helps anyone who experiences similar difficulty.