Example of boolean input type in node html file?

Well as Colin said, search his example for unzip

to give you a nudge - this is whats required...

  • In your html file
    • in the defaults...
      • myBool: { value: false },
      • myBoolType: { value: "bool" },
    • in oneditprepare()...
      • $("#node-input-myBool").typedInput({ default: 'bool', types: ['bool', 'msg', 'flow', 'global', 'env'], typeField: $("#node-input-myBoolType") });
    • in the html part (form-row)...
      • <input type="text" id="node-input-myBool"> <input type="hidden" id="node-input-myBoolType">
  • In your js file...
    • At initialisation, near the top, just below RED.nodes.createNode(this,config);...
      • node.myBool = config.myBool;
      • node.myBoolType = config.myBoolType;
    • later on (usually inside node.on("input", function(){ ...}) )...
      • let myBool = RED.util.evaluateNodeProperty(node.myBool, node.myBoolType, node, msg)
      • now use myBool as required in your logic (be prepared for users sending duff values though - so I recommend a sanity check on the value of mybool - perhaps even be a good citizen & call node.error("power is not a boolean value", msg) to inform the runtime of this error

Rinse and repeat as many for as many fields you want.


Umm... "it should always be true OR false"? - that is still a choice :smiley: :smiley:

The point of the typedInput is to permit the user to make that choice both inside your node (at design time in your UI) AND outside of it (by allowing the user/runtime to pass in true or false instead of "hard coding it").

That said, there are times it doesn't make sense to provide a choice (for example when a choice should never change once the node is initialized)