Beginner needs help

#1

Hello, i'm just starting on nodered and I have a problem. I'm creating a custom node but can't get the js file to work. In my html file i have this :

<div class="form-row">
    <input type="text" id="node-input-finalMsg" name="Message Final"/>
</div>

And in my js file :

module.exports = function (RED) {
    function AffichageNode(config) {
        RED.nodes.createNode(this, config);
        var node = this;
        this.finalMsg = config.finalMsg;
        this.on('input', function () {
            console.log(node.finalMsg)
        });
    }
    RED.nodes.registerType("Affichage", AffichageNode);
}

But if i run this code I get an "undefined" in the console. can someone help?

0 Likes

#2

Is that your entire html file?

Its missing the <script> parts ( see https://nodered.org/docs/creating-nodes/node-html)

As you want to take something from the configuration part you should also look at the "Configuration Nodes" page. https://nodered.org/docs/creating-nodes/config-nodes

0 Likes

#3

this is a sample, not the entire html, here my html file complete

<script type="text/javascript">
//stuff
    RED.nodes.registerType('Affichage', {
        category: 'Gertrude',
        color: '#91db85',
        defaults: {
            name: { value: "" }
        },
        inputs: 1,
        outputs: 1,
        icon: "affichage.png",
        label: function () {
            return this.name || "Affichage";
        },     
        oneditprepare: function() {
            //stuff
        },
        oneditcancel: function(){
           //stuff
        },
        oneditsave: function(){
            //stuff                   
        }
    });
</script>

<script type="text/x-red" data-template-name="Affichage">
//html here
 <div class="form-row">
    <input type="text" id="node-input-finalMsg" name="Message Final"/>
</div>
</script>

<script type="text/x-red" data-help-name="Affichage">
</script>
0 Likes

#4

You need to include finalMsg in the defaults object so the editor knows this is a property to save to the node configuration.

0 Likes

#5
RED.nodes.registerType('Affichage', {
        category: 'Gertrude',
        color: '#91db85',
        defaults: {
            finalMsg: { value: ""},
            name: { value: "" }
        },
        inputs: 1,
        outputs: 1,
        icon: "affichage.png",
        label: function () {
            return this.name || "Affichage";
        },

This is what I did and I still get the undefined

0 Likes