Creating a notification in the Admin UI
Published: |
Updated:
| by Julian Knight Reading time ~1 min.
📖 Kb
| 📎
Development
| 🔖
Node-RED, Node.JS, JavaScript
Node-RED’s admin UI has a built-in notification (toast) pop-up message feature. This article explains how to use it when creating custom nodes as it isn’t currently well documented.
RED.notify('Your message here', options)
This can be called from the script in your admin ui code <nodeName>.html
.
By default, the notification will disappear after a few seconds.
Options 🔗︎
type
: {success|warning|error=} Adds style to the message box.fixed
: {boolean=false} Defaults to false, the notification will auto-remove after a few seconds.modal
: {boolean=false} If true, no other user interactions are allowed until the notification has cleared.timeout
: {ms=5000}: Specify the time in milliseconds a non-fixed notification will be displayed for.id
: {string=} Allows a notification to be updated.width
: {px=} Desired width in pixels. (Will be limited to the parent width)
Methods 🔗︎
.close()
: Close the notification (useful iffixed
option istrue
).update
hideNotification
showNotification
Example 🔗︎
let myNotification = RED.notify('My message in a box', {
modal: true,
fixed: true,
type: 'warning',
buttons: [
{
'text': 'cancel',
'click': function(e) {
myNotification.close()
}
},
{
'text': 'okay',
'class': 'primary',
'click': function(e) {
myNotification.close()
},
},
],
})
References 🔗︎
- https://discourse.nodered.org/t/node-red-admin-ui-display-message-to-user/12290
- https://github.com/node-red/node-red/blob/ccc3809daa3b03e7171cb6f4ccf4d6e0f1188bef/packages/node_modules/%40node-red/editor-client/src/js/ui/notifications.js#L16
- https://github.com/node-red/node-red/wiki/API-Reference (old but has some things not documented elsewhere)