How to access a config nodes data while being in the parent edit dialog (oneditprepare function)?
--
http://nodered.org
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.
<script type="text/javascript">
RED.nodes.registerType('knx-write',{
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value:""},
groupaddress: {value:""},
groupaddresses: { value:"", type:"group-addresses"},
dpt: {value:"1"}
},
oneditsave: function() {
var mytype = $("#node-config-input-groupaddress").typedInput('type');
if (mytype !== "other") {
$("#node-config-input-groupaddress").typedInput('value',mytype);
}
this.groupaddress = $("#node-config-input-groupaddress").typedInput('value');
this.name = $("#node-config-input-groupaddress").typedInput('label');
},
oneditprepare: function() {
console.log(this);
var previous = null;
// Get the config node id from the select box:
var configNodeElement = $('node-input-groupaddresses');
console.log("configNodeElment: ", configNodeElement);
var configNodeID = $('node-input-groupaddresses').val();
console.log("configNodeID", configNodeID);
// Get the config node using the ID:
var configNode = RED.nodes.node(configNodeID);
console.log("configNode: ", configNode);
// todo: replace with config node data:
var blist = [
{value:'{ "ga":"1/2/3", "dpt":"1"}',label:"Name1",hasValue:false},
{value:'{ "ga":"4/5/6", "dpt":"2"}',label:"Name2 Kueche",hasValue:false},
{value:'{ "ga":"5/6/7", "dpt":"3"}',label:"Name3 Bad",hasValue:false}
];
var groupAddressType = "custom";
for (var i in blist) {
if (this.groupaddress == blist[i].value) {
groupAddressType = this.groupaddress;
}
}
$("#node-config-input-groupaddress").typedInput({
default: this.groupaddress,
types:blist
});
},
inputs:1,
outputs:1,
icon: "file.png",
label: function() {
return this.name||"knx-write";
}
});
</script>
<script type="text/javascript">
RED.nodes.registerType('group-addresses',{
category: 'config',
defaults: {
csv: {value:"",required:true},
name: {value:"All My Group Addresses"}
},
label: function() {
return this.name || 'Group Addresses';
}
});
</script>
<script type="text/x-red" data-template-name="group-addresses">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-config-input-csv"><i class="icon-bookmark"></i>Group Addresses as CSV</label>
<input type="text" id="node-config-input-csv">
</div>
</script>
<script type="text/x-red" data-template-name="knx-write">
<div class="form-row">
<label for="node-input-groupaddresses"><i class="icon-tag"></i> Group Addresses Set</label>
<input type="text" id="node-input-groupaddresses">
</div>
<div class="form-row">
<label for="node-input-groupaddress"><i class="icon-tag"></i> Group Address</label>
<input type="text" id="node-config-input-groupaddress" style="width:100px">
</div>
</script>
<script type="text/x-red" data-help-name="knx-write">
<p>A simple node for group address selection</p>
</script>