Configuration Node displays Node ID and not the result of the label function

#1

The issue is probably something obvious but my code looks close to the example from https://nodered.org/docs/creating-nodes/config-nodes.

Behavior:
After deploying the flow, the config node within in the select element displays the node id rather than the function result from the label.

Screenshot

Code:

<script type="text/javascript">
RED.nodes.registerType('server',{
    category: 'config',
    credentials: {
        username: {type: "text", required:true},
        password: {type: "password"}
    },
    defaults: {
        host: {value:"localhost",required:true},
    },
    label: function() {
        return this.host + ' (' + this.credentials.username + ')';
    }
});
<script type="text/x-red" data-template-name="server">
<div class="form-row">
    <label for="node-config-input-host"><i class="fa fa-server"></i> Host</label>
    <input type="text" id="node-config-input-host" placeholder="Host">
</div>
<div class="form-row">
    <label for="node-config-input-username"><i class="fa fa-user-circle"></i> Username</label>
    <input type="text" id="node-config-input-username" placeholder="Username">
</div>
<div class="form-row">
    <label for="node-config-input-password"><i class="fa fa-user-secret"></i> Password</label>
    <input type="password" id="node-config-input-password" placeholder="Password">
</div>
0 Likes

#2

You have not included a picture of the Config node's edit panel, but I'm guessing you don't have a "name" field defined? I think the default behavior in the non-config node is to show the config node's name, and if not found use the id instead... Why the "label" function is not being used instead of the name might be a bug (or it might be that the label function is only used within the flow editor, not the edit panel)?

0 Likes

#3

That is correct, I don't have a name field: just host, username and password.

I am hoping someone on the forum can help determine if it is a bug or help identify the error in my code. It's probably something with my code since I see other 3rd party nodes working fine.

0 Likes

#4

You cannot use this.credentials.anything in the label as credentials are not generally available to the editor. You are probably getting an error in the browser's JavaScript console about trying to reference username of undefined.

0 Likes

#5

This looks to be the case. I checked the JavaScript console and there were errors and I removed the "this.credentias.username" and all is working.

0 Likes