ThingsBoard: How to add Confirm Box to Switch Control widget (tb-switch)?

483 views Asked by At

How can I add a prompt to confirm action using window.confirm() to the existing Switch Control widget, tb-switch on ThingsBoard?

I want it to work in such a way that before updating the switch value,

if(Switch is currently "ON"){
    var off =window.confirm("Confirm OFF?");
    if(off){
        Turn switch off
    }
    else{
        Switch remains on
    }
}
    
else if(Switch is currently "OFF"){
    var on =window.confirm("Confirm ON?");
    if(on){
        Turn switch on
    }
    else{
        Switch remains off
    }
}
1

There are 1 answers

0
Panagiotis Giannelos On

Do it the way i did. Add a custom action on the switch widget that show a pop up for switch position confirmation, then on "verify action" button click make an rpc call with the state of the switch.