Hi,
I used the first node example from the Node-RED documentation to wrote a first little node. Thanks for that easy to understand example anyway. I enhanced the example to not only use msg.payload as input, but a configurable field. This should be an easy exercise.
My field is named inField
. It and a hidden -type
field are created as documented. In oneditprepare
I defined some additional input parameters:
$('#node-input-inField').typedInput({
type: 'msg',
types: ['str', 'msg', 'flow', 'global', 'jsonata', 'env'],
typeField: '#node-input-inField-type',
});
<div class="form-row">
<label for="node-input-inField"><i class="fa fa-cog"></i> Input</label>
<input type="text" id="node-input-inField" placeholder="...">
<input type="hidden" id="node-input-inField-type">
</div>
I also wrote an on event to fetch the change of the type.
$('#node-input-inField').on('change', function (event, type, value) {...}
The edit mask looks well, event is triggered.
However, it's not clear to me how to store and handle input field type changes and let Node-RED handle this. Maybe I didn't find it, or the docu is somewhat short on this part, or it must be that obvious, that it's not even worse to mention it.
Let's say the user selects type 'jsonata' and value '"ABCD"' (I know it's a constant that could be done by a string, but hey, it's just an example) . The event is fired. Where and how do I have to store the new type, so that it remains? NR stores the value automatically, but not the changed type.
And in addition, a 2nd question:
I guess I have to perform the data interpretation myself. So, in my .js, on input, I get the value "ABCD" in the config object, but not the type (str, msg, jsonata, ...).
Are there examples how to do this?