Node-red Dashboard ui-template not able to send message/payload

Hi,
iI searched and tryed many options to get a payload out of this ui-template-node.
Wether version 1 or Version 2 is sending an outpout to a Debug-node.
have no more idea what´s wrong?
Using v3.1.3 and old Dashboard.
image

Version 1

 <span class="toggle">
    <input type="checkbox"id="checkbox1" onchange="toggleState(this)">
    <label data-off="OFF" data-on="ON"></label>
</span>
<script>
  function toggleState(checkbox) {
    var msg = { payload: "" }; 
    if (checkbox.checked) 
   {
        
        msg.payload = "TRUE";
    } 
else
    {
        msg.payload = "FALSE";
    }
        node.send(msg);
  }
</script>

Version 2

   <span class="toggle">
        <input type="checkbox" onclick="onClickHandler(msg)" id="box3" />
        <label data-off="AUS" data-on="AN"></label>
        
    </span>

<script>
function onClickHandler(msg) 
{
var offValue = event.target.getAttribute('data-off');
var onValue = event.target.getAttribute('data-on');
var msg = { payload: "" };
if (offValue === 'AUS')
{
msg.payload = "TRUE";
return msg;
} 
else if (onValue === 'AN') 
{
msg.payload = FALSE;
return msg;
}

}
</script>

Thank you for your Idea:
steelbuddy

Try the angularjs ng-model and ng-change
e.g.

<span class="toggle">
    <input ng-model="mycheckbox1" type="checkbox"id="checkbox1" ng-change="toggleState(mycheckbox1)">
    <label data-off="OFF" data-on="ON"></label>
</span>
<script>
this.scope.toggleState = function(checked) { 

    if (checked){
        checked = "TRUE";
    }else{
        checked = "FALSE";
    }
    this.send({payload:checked})
}
</script>

Thx, it works :+1:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.