Count checked checkboxes in node-red dashboard

#1

Hello, I´m using the node-red dashboard for a cocktailmachine.
First I need to select 10 from 20 ingredients with checkboxes from the form-node. Can I count the selected checkboxes before submitting the values?

Is it also possible with switches from the form-node?

If no, how can I count them after submitting?

Thank´s for helping

0 Likes

#2

Hi Partyarti!
A cocktailmachine sounds awesome! Using the form-node you can't easily count the selected checkboxes before submitting. You'd have to create a ui-template that parses your html and count the md-icons that have been selected.

Counting after submitting is much easier, you could use a function node with the following:

let count = 0
for (let x in msg.payload) {
    if (msg.payload[x] === true){
        count++
    }
}
msg.count = count
return msg;

Another option would be using the split node followed by a switch node (set to: is true) followed by a node-red-contrib-message-counter node.

Cheers!

0 Likes