How to access a config nodes data while being in the parent edit dialog (oneditprepare function)

844 views
Skip to first unread message

Florian Maetschke

unread,
Aug 15, 2016, 3:26:15 PM8/15/16
to Node-RED
How to access a config nodes data while being in the parent edit dialog (oneditprepare function)?


Nicholas O'Leary

unread,
Aug 15, 2016, 4:16:03 PM8/15/16
to Node-RED Mailing List
Let's assume the 'parent' has a property called 'myConfig' that references the config node.

  // Get the config node id from the select box:
  var configNodeID = $('node-input-myConfig').val();
  // Get the config node using the ID:
  var configNode = RED.nodes.node(configNodeID);

You will need to consider what to do when the select box is currently on the 'add new xyz' option (the returned id is '_ADD_').

Nick


On 15 August 2016 at 20:26, 'Florian Maetschke' via Node-RED <node...@googlegroups.com> wrote:
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.

Florian Maetschke

unread,
Aug 16, 2016, 3:27:15 PM8/16/16
to Node-RED
Thx again Nick!
Hmm this seems not to work. I get no configNodeId. But the element is found. Here is the code. Maybe you directly see my mistake?


<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>





The output after opening the edit dialog of knx-write is:

  1. ()
  2. _def:Object
  3. _ports:Array[1]
  4. changed:false
  5. dirty:false
  6. dpt:"1"
  7. groupaddress:"{ "ga":"5/6/7", "dpt":"3"}"
  8. groupaddresses:"19227084.cf045f" <-- the value of the config node
  9. h:30
  10. id:"6eb29534.26e4dc"
  11. inputs:1
  12. name:""
  13. outputs:1
  14. ports:Array[1]
  15. selected:true
  16. type:"knx-write"
  17. valid:true
  18. w:120
  19. x:292
  20. y:99
  21. z:"ca347ef7.4cd5b"
  22. __proto__:Object

configNodeElment:  [prevObject: m.fn.init[1], context: document, selector: "node-input-groupaddresses"]
configNodeID undefined
configNode:  null
Reply all
Reply to author
Forward
0 new messages