Saving values when editing a node

722 views
Skip to first unread message

Max Hadley

unread,
May 29, 2014, 6:40:52 PM5/29/14
to node...@googlegroups.com
I have just hit an inexplicable problem! I am writing a node, which has a property a bit like the payload source of the inject node. In the node editor, I have a select input which allows me to choose between two sources of the property, which is a device address. One source is the message topic; the other is a string entered in the node editor. I'm using an oneditprepare() function to hide the text field for the address when the message source is selected. This all seems to be working, and I see in the browser the values of the properties change. However, node-RED does not see the new values when I deploy the edit, only when I quit and re-start node-RED, presumably reloading from the flow file.

Is this a known bug? I'm using an oldish (May 5th) commit from Github, 671723374d, but other nodes, such as inject nodes, are working as expected.

My code is shamelessly cribbed from the inject node!

Max

The html looks like this:

<!-- This is a transmitter node for lighting-type commands and the devices that receive tham -->
<script type="text/x-red" data-template-name="rfx-lights">
    <div class="form-row node-input-port">
        <label for="node-input-port"><i class="icon-bullhorn"></i> Serial Port</label>
        <input type="text" id="node-input-port">
    </div>
    <div class="form-row node-input-topic">
        <label for="node-input-topicSource"><i class="icon-envelope"></i> Address</label>
        <select id="node-input-topicSource" style="width:73% !important">
          <option value="msg">get address from message topic</option>
          <option value="node">send all commands to the same address</option>
        </select>
    </div>
    <div class="form-row" id="node-input-row-topic">
        <label for="node-input-topic"></label>
        <input type="text" id="node-input-topic" placeholder="protocol/device address/unit address">
    </div>
    <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>
</script>

<script type="text/javascript">
    RED.nodes.registerType('rfx-lights', {
        category: 'output',
        defaults: {
            name: {name:""},
            port: {type:"rfxtrx-port", required:true},
            topicSource: { value:"msg", required:true },
            topic: { value:"" }
        },
        color:"BurlyWood",
        inputs:1,
        outputs:0,
        icon: "serial.png",
        align: "right",
        label: function() {
            var rfxtrxNode = RED.nodes.node(this.rfxtrx);
            return this.name || (rfxtrxNode ? rfxtrxNode.label() : "rfx-lights");
        },
        labelStyle: function() {
            return this.name ? "node_label_italic" : "";
        },
        oneditprepare: function() {
            if (this.topicSource == null) {
                if (this.topic == "") {
                    this.topicSource = "msg";
                } else {
                    this.topicSource = "node";
                }
            }
            $("#node-input-topicSource").change(function() {
                var id = $("#node-input-topicSource option:selected").val();
                if (id == "node") {
                    $("#node-input-row-topic").show();
                } else {
                    $("#node-input-row-topic").hide();
                }
            });
            $("#node-input-topicSource").val(this.topicSource);
            $("#node-input-topicSource").change();
        },
    });
</script>

Nicholas O'Leary

unread,
May 29, 2014, 6:50:33 PM5/29/14
to node...@googlegroups.com
Hi Max,

at first glance, I think the issue is the following code in oneditprepare:

                if (this.topic == "") {
                    this.topicSource = "msg";
                } else {
                    this.topicSource = "node";
                }

you shouldn't be setting node properties in oneditprepare.

If that isn't it, can you send me (directly) your node files so I can run it?

Nick




--
http://nodered.org
---
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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Max Hadley

unread,
May 30, 2014, 3:02:51 AM5/30/14
to node...@googlegroups.com
Nick (and anyone else who is interested),

I quickly tried out your the suggestion of commenting out the default initialisation code, which did not fix the issue I'm seeing. If you or anyone else wants to take a look, the code for this node, which is intended to talk to an RFXCOM rfxtrx433 remote control transceiver, is in my Github node-red-nodes repository, branch rfxcom: https://github.com/maxwellhadley/node-red-nodes/tree/rfxcom. The node files are in io/rfxcom/

To try this in anger you will need my fork of node-rfxcom: https://github.com/maxwellhadley/node-rfxcom

All still very much a work in progress!

Thanks,

Max

Max Hadley

unread,
May 30, 2014, 5:21:05 PM5/30/14
to node...@googlegroups.com
Nick,

I've found the problem. My node's 'close' event handler was throwing an undefined variable exception, which was being caught somewhere and turned into an innoccuous warning message, but clearly the node close function itself was not running to completion. All fixed now.

Memo to self: stop coding no later than 11pm!

Cheers,

Max
Reply all
Reply to author
Forward
0 new messages