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

Reset of SwitchFor control does not work

3 Answers 249 Views
Switch
This is a migrated thread and some comments may be shown as answers.
Jean
Top achievements
Rank 1
Jean asked on 25 May 2020, 01:11 AM

I have a form with a couple of switchfor controls on them. They are bond to Boolean properties of my model. When calling a reset on the form, these controls do not revert back to the original value as expected.

 

<div class="col-1">
                        <div class="form-group">
                            <label asp-for="DoNotContact">Ne pas contacter</label><br />
                            @(Html.Kendo().SwitchFor(m => m.DoNotContact)    )
             </div>

 </div>

What am I doing wrong?

 

 

 

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 26 May 2020, 12:11 PM

Hello Jean,

I would suggest you call the refresh() method of the Switch after the form has been reset. This will reset the Switch to its default state.

 $("#switch").data("kendoMobileSwitch").refresh();

Let me know if you have any questions.

Regards,
Nikolay
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
Jean
Top achievements
Rank 1
answered on 27 May 2020, 01:27 AM

Hi Nicolay,

 

I am not using KendoMobileSwitch. As stated in my question, I am using KendoSwitch and it seems that there is no refresh() method on this control. The lack of consistency between controls and the minimalist documentation is quite frustrating. I solved my problem by manually checking the original value and if different from the displayed state, i call the toggle method.  Here is my script:

 var dnc = $("#DoNotContact").data("kendoSwitch");
        if (dnc.checked != "@Model.DoNotContact")
            dnc.toggle();

 

Not elegant but it works...

 

 

0
Nikolay
Telerik team
answered on 28 May 2020, 01:43 PM

Hello Jean,

Thank you fr sharing the solution you came up with. I have prepared a small Dojo demo demonstrating how to incorporate the toggle() method to reset the Switch on submitting the form.

Regards,


Nikolay
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.
Tags
Switch
Asked by
Jean
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Jean
Top achievements
Rank 1
Share this question
or