Button "clicked" during first render template

depending to my plugin vm:

the button seems to be clicked e.g. the send function is called while the page is rendered the first time. Did I something wrong?
As a workaround I send an addidtionally "boot" to fix this behavior.

Did you initially try with

<button class="btnToggle" data-bind="click: send, style: {'background-color': bedPower() != 1 ? 'red' : 'green' }"></button>

click may send a "toogle" so I used

<button class="btnToggle" data-bind="click: send("toggle"), style: {'background-color': bedPower() != 1 ? 'red' : 'green' }"></button>

but the behavior doesn't change. In the python model I still reveive a "toggle" followed by the "boot"

The pretty funny stuff is that I'm playing around with flask, bootstrap and knockout with a complete different and much simpler environment and got the same behavior.

IIRC with knockout if you need to pass arguments to the function outside of bound data then you definitely need to wrap it in a function like you are doing. Just click: send("toggle") will definitely cause the function to be run on initial load.

1 Like