Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Button group - show node status #1333

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading