Hi,
I have used NodeRED for a number of years, but never needed to create my own custom node... until now.
I'm on NodeRED 3.0.2
I have a 'name' property in the data-template and also a multi-select typedInput. I have created the JS and HTML files, all looks nice and works well if I restart NodeRED.
However, I'd like my node to read the correct, current value of the multiselect, this is changed when the flow is deployed, but the JS sees the old value.
I attach a simplified version of my code. Any help is gratefully received.
my .html file
<script type="text/javascript">
RED.nodes.registerType('m2et-events-xml',{
category: 'Lownto',
color: 'rgb(231, 231, 174)',
defaults: {
name: {value:"events handler"},
events: {value:""}
},
inputs:0,
outputs:0,
icon: "white-globe.svg",
label: function() {
return this.name||"m2et-events-xml";
},
oneditprepare: function () {
$("#node-input-events").typedInput({
type:"events",
types: [{
value: "events",
multiple: "true",
options: [
{ value: "adminhtml_customer_save_after", label: "adminhtml_customer_save_after"},
{ value: "catalog_category_save_after", label: "catalog_category_save_after"},
]
}]
});
}
});
</script>
<script type="text/html" data-template-name="m2et-events-xml">
<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-events"><i class="fa fa-tag"></i>Enabled Events</label>
<input type="text" id="node-input-events">
</div>
</script>
<script type="text/html" data-help-name="m2et-events-xml">
<p>My first node</p>
</script>
The relevant part of my .js
module.exports = function (RED) {
let xmlbuilder = require('xmlbuilder');
function HttpXmlRequestResponse(config) {
RED.nodes.createNode(this, config);
let node = this;
let events = config.events;
// NOTE : This one outputs the updated value per the multi-select if you change it in admin and deploy.
node.warn("set events var to " + events);
RED.httpNode.get('/my_endpoint, function (req, res) {
// NOTE : 'events' here is always the value as per when nodeRED is started, so it's wrong until I restart NodeRED
let xmlResponse = generateEventsXmlResponse(events);
if (xmlResponse) {
res.set('Content-Type', 'text/xml');
res.send(xmlResponse);
} else {
res.sendStatus(404);
}
});
function generateEventsXmlResponse(area, events) {
// 'events' is always stale until a restart of NodeRED
}
}
RED.nodes.registerType('m2et-events-xml', HttpXmlRequestResponse);
};