Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_form.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. module.exports = function(RED) {
  2. var ui = require('../ui')(RED);
  3. function FormNode(config) {
  4. RED.nodes.createNode(this, config);
  5. var node = this;
  6. var group = RED.nodes.getNode(config.group);
  7. if (!group) { return; }
  8. var tab = RED.nodes.getNode(group.config.tab);
  9. if (!tab) { return; }
  10. node.on("input", function(msg) {
  11. node.topi = msg.topic;
  12. });
  13. var done = ui.add({
  14. node: node,
  15. tab: tab,
  16. group: group,
  17. forwardInputMessages: false,
  18. storeFrontEndInputAsState: false,
  19. control: {
  20. type: 'form',
  21. label: config.label,
  22. order: config.order,
  23. value: config.payload || node.id,
  24. width: config.width || group.config.width || 6,
  25. height: config.height || config.splitLayout == true ? Math.ceil(config.options.length/2) : config.options.length,
  26. options: config.options,
  27. formValue: config.formValue,
  28. submit: config.submit,
  29. cancel: config.cancel,
  30. splitLayout: config.splitLayout || false,
  31. sy: ui.getSizes().sy,
  32. cy: ui.getSizes().cy,
  33. className: config.className || '',
  34. },
  35. beforeSend: function (msg) {
  36. var t = RED.util.evaluateNodeProperty(config.topic,config.topicType || "str",node,msg) || node.topi;
  37. if (t) { msg.topic = t; }
  38. }
  39. });
  40. node.on("close", done);
  41. }
  42. RED.nodes.registerType("ui_form", FormNode);
  43. };