Search code examples
kendo-uikendo-asp.net-mvc

When changing a kendoswitch programmatically the label does not change


I have a KendoSwitch set to "On". I run the code below and it's checked status does go to false but the label does not change. I would expect it to say "Off". I cannot work out why as when i run code to check its status it is set as false after running the below code:

var thatSwitch = $("#" + 'KendoDemo').data("kendoSwitch");

thatSwitch.check(false);

Solution

  • You need to use the toggle method on the switch. Like so:

    var thatSwitch = $("#" + 'KendoDemo').data("kendoSwitch");
    thatSwitch.toggle();
    

    The documentation:

    https://demos.telerik.com/aspnet-core/switch/api

    or

    https://docs.telerik.com/kendo-ui/api/javascript/ui/switch/methods/toggle