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_dropdown.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const statestore = require('../store/state.js')
  2. module.exports = function (RED) {
  3. function DropdownNode (config) {
  4. // create node in Node-RED
  5. RED.nodes.createNode(this, config)
  6. const node = this
  7. // which group are we rendering this widget
  8. const group = RED.nodes.getNode(config.group)
  9. const evts = {
  10. onChange: true,
  11. beforeSend: function (msg) {
  12. if (msg.ui_update) {
  13. const update = msg.ui_update
  14. if (update.options) {
  15. // dynamically set "options" property
  16. statestore.set(group.getBase(), node, msg, 'options', update.options)
  17. }
  18. if (typeof update.label !== 'undefined') {
  19. // dynamically set "label" property
  20. statestore.set(group.getBase(), node, msg, 'label', update.label)
  21. }
  22. if (typeof update.multiple !== 'undefined') {
  23. // dynamically set "label" property
  24. statestore.set(group.getBase(), node, msg, 'multiple', update.multiple)
  25. }
  26. }
  27. if (msg.options) {
  28. // backward compatibility support
  29. statestore.set(group.getBase(), node, msg, 'options', msg.options)
  30. }
  31. return msg
  32. }
  33. }
  34. // inform the dashboard UI that we are adding this node
  35. group.register(node, config, evts)
  36. }
  37. RED.nodes.registerType('ui-dropdown', DropdownNode)
  38. }