How to access selection from drop down property

I can access the text input field value, but the drop down selection from the properties windows is undefined.

Below is my code, how can I access which drop down menu was selected?

tester.html

<script type="text/javascript">
    RED.nodes.registerType('tester', {
        category: 'test nodes',
        color: '#C0C0C0',
        defaults: {
            name: {value: ""},
            instanceId: {value: "", required: true}
        },
        inputs: 1,
        outputs: 1,
        icon: "font-awesome/fa-handshake-o",  
        label: function() {
            return this.name || "tester";
        },
        labelStyle: function() {
            return this.name ? "node_label_italic" : "";
        },
        defaults:{
            JoinID: {value:"", required:true }
        }
    });
</script>

<script type="text/html" data-template-name="tester">
    <!-- Join ID Input -->
    <div class="form-row">
        <label for="node-input-JoinID"><i class="icon-tag"></i> Join ID</label>
        <input type="text" id="node-input-JoinID" placeholder="Join ID">
    </div>
    <!-- drop down -->
    <div class="form-row">
        <label for="node-input-makeSelection"><i class="icon-tag"></i> Make Selection</label>
        <select value="" select id="node-input-makeSelection">
            <option value="Run System Update">Run System Update</option>
            <option value="Clear All Node-RED Flows">Clear All Node-RED Flows</option>
        </select>
    </div>
</script>

<script type="text/html" data-help-name="tester">
    <p>This node is a local tester node</p>
</script>

tester.js

module.exports = function (RED) {
    function TesterNode(config) {
        RED.nodes.createNode(this, config);
        var node = this;
        this.JoinID = config.JoinID;//
        //this.makeSelection = RED.nodes.getNode(config.makeSelection);//
        this.makeSelection = config.makeSelection;//


        // Your node logic here...

        this.on('input', function (msg) {

            node.warn("join id is: " + node.JoinID);//works ok
            node.warn("makeSelection is: " + node.makeSelection);//makeSelection is: undefined
        });
    }

    RED.nodes.registerType("tester", TesterNode);
};

You don't have a property named makeSelection in your defaults.

1 Like

And indeed two sets of defaults. (Not good)

1 Like

Didn't even spot that :eagle::eye:

edit: i tried adding the following which appeard to have worked fine.

defaults:{
            JoinID: {value:"", required:true },
            makeSelection: { value: "", required: true },
        }

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.