Skip to content

Commit

Permalink
Merge pull request #1333 from bartbutenaers/button-group-status
Browse files Browse the repository at this point in the history
Button group - show node status
  • Loading branch information
joepavitt authored Oct 4, 2024
2 parents 0b233e0 + a8aa69b commit a0a8fde
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions nodes/widgets/ui_button_group.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,31 @@ module.exports = function (RED) {
// which group are we rendering this widget
const group = RED.nodes.getNode(config.group)

// Keep the code of this function in sync with the client-side function
function findOptionByValue (val) {
const opt = config.options?.find(option => {
if (typeof (val) === 'object') {
return (JSON.stringify(val) === JSON.stringify(option.value))
} else {
return option.value === val
}
})
if (opt) {
return opt
}
return null
}

const evts = {
onChange: true,
beforeSend: function (msg) {
if (typeof msg.payload !== 'undefined') {
const option = findOptionByValue(msg.payload)
if (option) {
node.status({ fill: 'blue', shape: 'dot', text: option.label || option.value })
}
}

if (msg.ui_update) {
const update = msg.ui_update
if (typeof update.options !== 'undefined') {
Expand Down
1 change: 1 addition & 0 deletions ui/src/widgets/ui-button-group/UIButtonGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export default {
this.$socket.emit('widget-change', this.id, value)
}
},
// Keep the code of this function in sync with the server-side function
findOptionByValue: function (val) {
const opt = this.options?.find(option => {
if (typeof (val) === 'object') {
Expand Down

0 comments on commit a0a8fde

Please sign in to comment.