Can't retrieve a textarea property's value

Hi,

Looking at similar questions I found only this one, which looks abandoned since August...

So,, summarizing my issue, I am creating a new node... and though using a textarea for one of the properties, and after sometime, decided to search for help.

My environment is

  • Node-RED version: v1.0.6
  • Node.js version: v8.10.0
  • Linux 5.3.0-1022-azure x64 LE

To provide a real example, here is my package.json:

{
  "name": "my-sample-package",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "jmn",
  "license": "ISC",
  "node-red": {
    "nodes": {
      "myexec": "myexec.js"
    }
  }
}

The myexec.html file is:

<script type="text/javascript">
  RED.nodes.registerType('myexec',{
    category: 'Learning',
    color: '#008000',
    defaults: {
      name: {value:""},
      command: { value:"" }
    },
    inputs:1,
    outputs:2,
    icon: "function.png",
    label: function() {
      return this.name||"myexec";
    }
  });
</script>

<script type="text/html" data-template-name="myexec">
    <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-input-command"><i class="icon-tag"></i> Command</label>
      <textarea id="node-input-command" rows="10"></textarea>
    </div>
</script>

<script type="text/html" data-help-name="myexec">
    <p>A simple to execute shell commands</p>
</script>

And the myexec.js:

module.exports = function(RED) {
  function Exec(config) {
    RED.nodes.createNode(this,config);
    var node = this;
    node.on('input', function(msg) {
        const { spawn, exec } = require('child_process');
        //const ls = spawn('ls', ['-lh', '/usr']);

        console.log( node )

        const cmd = exec(node.command)

        var m1 = { payload: "", _msgid: msg._msgid }
        var m2 = { payload: "", _msgid: msg._msgid }

        cmd.stdout.on('data', (data) => {
           //m1.payload=String.fromCharCode.apply(null, data)
           //msg.payload = `${data}`
           m1.payload = data.toString()
        });

        cmd.stderr.on('data', (data) => {
           //m2.payload=String.fromCharCode.apply(null, data)
           m2 = { payload: data.toString() }
        });

        cmd.on('close', (code) => {
           console.log(`child process exited with code ${code}`);
        });
        //node.send(msg);
        node.send( [ m1, m2 ] )
      });
    }
    RED.nodes.registerType("myexec",Exec);
}

I then created 2 single nodes: an injector and my myexec node:

[{"id":"eeb01a85.e0abd8","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"199d6185.eed5fe","type":"inject","z":"eeb01a85.e0abd8","name":"","topic":"","payload":"This Is @ TEST!!!!","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":160,"wires":[["5acc52df.23e6bc","ac9bbefa.061f"]]},{"id":"dd2d79c6.69ee68","type":"debug","z":"eeb01a85.e0abd8","name":"Out","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":660,"y":140,"wires":[]},{"id":"7144cffd.d395c","type":"debug","z":"eeb01a85.e0abd8","name":"Err","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":640,"y":240,"wires":[]},{"id":"5acc52df.23e6bc","type":"debug","z":"eeb01a85.e0abd8","name":"Inp","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":400,"y":300,"wires":[]},{"id":"ac9bbefa.061f","type":"myexec","z":"eeb01a85.e0abd8","name":"Test","command":"ls /usr -l","x":450,"y":200,"wires":[["dd2d79c6.69ee68"],["7144cffd.d395c"]]}]

When I trigger a time event, I see the following on the console:

24 May 17:42:14 - [info] Server now running at http://127.0.0.1:1880/
Exec {
  id: 'ac9bbefa.061f',
  type: 'myexec',
  z: 'eeb01a85.e0abd8',
  _closeCallbacks: [],
  _inputCallback: [Function],
  _inputCallbacks: null,
  name: 'Test',
  _asyncDelivery: true,
  wires: [ [ 'dd2d79c6.69ee68' ], [ '7144cffd.d395c' ] ],
  _wireCount: 2,
  send: [Function] }
24 May 17:44:12 - [error] [myexec:Test] TypeError: "file" argument must be a non-empty string

I was expecting to see the command property, but it is nowhere to be seen...
Any idea?

Thanks in advance
José

Not sure it textarea is supported. Try a regular hidden input (like in many of the core nodes on GitHub) and use the onedit and onsave events (can't remember exact event names again, see core nodes) - to populate/save users input on the textarea to/from the hidden field.

Hey Steve,
I have used a textarea for the first time last week, so I expect it to work...

Hi José,
I haven't tried your code yet, but could it be that you have forgotten to copy the command (from the node config to the node instance itself)? I think you should add an extra line:

  function Exec(config) {
    RED.nodes.createNode(this,config);
    this.command = config.command;
    var node = this;

Bart

1 Like

Ah well spotted Bart.

1 Like

Thanks Bart,
It was definitely the problem :slight_smile: Got it working!

1 Like

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