This is a migrated thread and some comments may be shown as answers.

Set default switch messages

2 Answers 286 Views
Switch
This is a migrated thread and some comments may be shown as answers.
Barry
Top achievements
Rank 1
Barry asked on 29 May 2020, 03:29 PM

How can I set the checked/unchecked messages for my entire application or at least for the page?

Currently, I use something like:

<kendo-switch for="BoundProperty" checked="Model.BoundProperty"><messages checked="@Html.T("Common.YES")" unchecked="@Html.T("Common.NO")" /></kendo-switch>

 

It would be great if I didn't have to include the <messages /> tag each time.

2 Answers, 1 is accepted

Sort by
0
Accepted
Anton Mironov
Telerik team
answered on 02 Jun 2020, 02:07 PM

Hello, Barry,

Thank you for the provided code snippet.

In order to change messages to all Kendo UI Switches there are two approaches that you might take:

1. Try to override their prototype. This could happen with the help of the extend method that will change switches' messages globally in your application:

    $.extend(kendo.ui.Switch.prototype.options, {
        messages: {
            checked: "on",
            unchecked: "off"
        }
    });

2. Use the setOptions() method of the widget to change switches' messages on the current page:

 $(function () {
        var allSwitches = $(".k-switch input");

        $.each(allSwitches, function (key, value) {
            var currSwitch = $(value).getKendoSwitch();
            currSwitch.setOptions({
               messages: {
                checked: "aaa",
                unchecked: "bbb"
              }
            });
        });
    });

Furthermore, you can find the following article interesting that describes using the setOptions() method in more details:

https://docs.telerik.com/kendo-ui/api/javascript/ui/grid/methods/setoptions

Please let me know if you have any other questions.

Greetings,
Anton Mironov
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Barry
Top achievements
Rank 1
answered on 03 Jun 2020, 12:00 AM

Hi Anton,

Option 1 is perfect, just what I needed.

Thanks for your help.

Barry

Tags
Switch
Asked by
Barry
Top achievements
Rank 1
Answers by
Anton Mironov
Telerik team
Barry
Top achievements
Rank 1
Share this question
or