# Template widget checkbox toggle update issue

**URL:** https://discourse.nodered.org/t/template-widget-checkbox-toggle-update-issue/69729
**Category:** General
**Created:** [28 October 2022 11:46 UTC](https://discourse.nodered.org/t/template-widget-checkbox-toggle-update-issue/69729 "2022-10-28T11:46:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Mbessing](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mbessing/32/59136_2.png) [@Mbessing](https://discourse.nodered.org/u/Mbessing)
#### Post date: [28 October 2022 11:46 UTC](https://discourse.nodered.org/t/template-widget-checkbox-toggle-update-issue/69729/1 "2022-10-28T11:46:57Z")

</div>

Hi,

I'm creating a project in which I want to be able to check/uncheck a checkbox manually (by clicking) and also by an external source such as MQTT input etc. In my test I simulate the external source by an inject node currently.

I managed to find actually do this, although an issue sometimes occurs in which I have to refresh the page to see the updated checkbox. I found out it happens when I first toggle the checkbox manually and then afterwards with the inject node.

Does anyone know what may cause this issue? The problem does not occur if I only trigger it manually or only with the inject node.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e07fea1597bd9549c439afe7df6022a5f5729f1.png)

---

<div class="post-metadata">

### Author: ![knoepsche](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knoepsche/32/69450_2.png) [@knoepsche](https://discourse.nodered.org/u/knoepsche)
#### Post date: [28 October 2022 19:34 UTC](https://discourse.nodered.org/t/template-widget-checkbox-toggle-update-issue/69729/2 "2022-10-28T19:34:43Z")

</div>

When I had this issue it had something to do with the digest loop of angularjs. You can trigger the loop manually by

```auto
scope.$applyAsync(function(){
    ...;
});

```

An example would be:

```auto

<md-input-container>
    <md-checkbox ng-model="data">
        Checkbox in an md-input-container
    </md-checkbox>
</md-input-container>

<script>
    (function(scope) {
        scope.data = false;
        
        
        
        //handle arriving messages
        scope.$watch('msg', function(msg) {
            if(msg !== undefined && msg !== null){
                try{
                    switch(msg.topic) {
                        case "cbx setting":
                            scope.$applyAsync(function(){
                                scope.data = msg.payload;
                            });
                        break;

                        default:
                        break;
                    }
                }catch(err){
                    console.error(err);
                }
            }
        });
    })(scope);
</script>

```

Where you can check the checkbox by this message:

```auto
{payload:true, topic:"cbx setting"}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [27 December 2022 19:35 UTC](https://discourse.nodered.org/t/template-widget-checkbox-toggle-update-issue/69729/3 "2022-12-27T19:35:21Z")

</div>

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