From 778e0259c9ba43d22a5a5bdfb6d6d3a4d29a113e Mon Sep 17 00:00:00 2001 From: Joe Pavitt Date: Thu, 7 Mar 2024 14:58:12 +0000 Subject: [PATCH 1/2] Button-Group: Ensure type assignment for payload & update tests --- cypress/tests/widgets/button-group.spec.js | 2 +- nodes/widgets/ui_button_group.js | 5 +++++ ui/src/widgets/ui-button-group/UIButtonGroup.vue | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cypress/tests/widgets/button-group.spec.js b/cypress/tests/widgets/button-group.spec.js index be742a991..d59f31c93 100644 --- a/cypress/tests/widgets/button-group.spec.js +++ b/cypress/tests/widgets/button-group.spec.js @@ -15,7 +15,7 @@ describe('Node-RED Dashboard 2.0 - Buttons', () => { // Emitting Number cy.clickAndWait(cy.get('button').contains('Left')) cy.checkOutput('msg.topic', 'second-row') - cy.checkOutput('msg.payload', '0') + cy.checkOutput('msg.payload', 0) }) it('can have a selection made via msg.payload', () => { diff --git a/nodes/widgets/ui_button_group.js b/nodes/widgets/ui_button_group.js index 3874c9f4d..e0f1050cd 100644 --- a/nodes/widgets/ui_button_group.js +++ b/nodes/widgets/ui_button_group.js @@ -11,6 +11,11 @@ module.exports = function (RED) { onChange: true } + // loop over the options and ensure we've got the correct types for each option + config.options.forEach(option => { + option.value = RED.util.evaluateNodeProperty(option.value, option.valueType, node) + }) + // inform the dashboard UI that we are adding this node if (group) { group.register(node, config, evts) diff --git a/ui/src/widgets/ui-button-group/UIButtonGroup.vue b/ui/src/widgets/ui-button-group/UIButtonGroup.vue index c1042276f..a098c6f98 100644 --- a/ui/src/widgets/ui-button-group/UIButtonGroup.vue +++ b/ui/src/widgets/ui-button-group/UIButtonGroup.vue @@ -73,7 +73,7 @@ export default { this.selection = msg.payload }, onChange (value) { - if (value) { + if (value !== null && value !== undefined) { // Tell Node-RED a new value has been selected this.$socket.emit('widget-change', this.id, value) } From 4f4c6288fc8e7a69e5694523b767985beac98eb2 Mon Sep 17 00:00:00 2001 From: Joe Pavitt <99246719+joepavitt@users.noreply.github.com> Date: Tue, 12 Mar 2024 09:51:54 +0000 Subject: [PATCH 2/2] Update ui/src/widgets/ui-button-group/UIButtonGroup.vue Co-authored-by: Stephen McLaughlin <44235289+Steve-Mcl@users.noreply.github.com> --- ui/src/widgets/ui-button-group/UIButtonGroup.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/src/widgets/ui-button-group/UIButtonGroup.vue b/ui/src/widgets/ui-button-group/UIButtonGroup.vue index a098c6f98..48c175e34 100644 --- a/ui/src/widgets/ui-button-group/UIButtonGroup.vue +++ b/ui/src/widgets/ui-button-group/UIButtonGroup.vue @@ -73,7 +73,7 @@ export default { this.selection = msg.payload }, onChange (value) { - if (value !== null && value !== undefined) { + if (value !== null && typeof value !== 'undefined') { // Tell Node-RED a new value has been selected this.$socket.emit('widget-change', this.id, value) }