Telerik Forums
UI for ASP.NET MVC Forum
0 answers
323 views

Hi,

I have this code here inside the form and only code for the switch(), : 


<div class="create-section">
    @(
        Html.Kendo().Form<WeighmoreSouth32Web.Models.Role>()
            .Name("createForm")
            .HtmlAttributes(new { action = "Create", method = "POST" })
            .Validatable(v =>
            {
                v.ValidateOnBlur(true);
                v.ValidationSummary(vs => vs.Enable(true).TemplateId("validation-message"));
            })
            .Items(itemGroup =>
            {
                itemGroup.AddGroup().Layout("grid").Grid(g => g.Cols(3).Gutter(20)).Label("Role Info").Items(items =>
                {
                items.Add()
                .Field(f => f.RoleName)
                .Label(l => l.Text("Role Name"));
                items.Add()
                .Editor(e => e.Switch().Name("AddCustomer")).Field(f => f.AddCustomer)
                .Label(l => l.Text("Role Name*:"));
            });
        })

        )
   

</div>

 it is working fine for the textbox input but when I use switch to pass the true value it is passing it two times one true and other one false. But it does not do the same when switch is off, only passes the false value. Here is a picture of it. I did also tried some Js/Jquery code to bind it but it didn't worked as well. Please help. 

 

Rikki
Top achievements
Rank 1
 updated question on 26 Sep 2022
0 answers
552 views

I have a switch control, placed inside of a tab control, in a client detail template, as part of a grid.

I need to bind the switch checked property, to a value stored in the grids dataset, which is a Boolean. However, the code causes the error:-

Preprocessor directives must appear as the first non-whitespace character on a line

The code is:-

<script id="subsubdetailsTemplate" type="text/kendo-tmpl">

@(Html.Kendo().TabStrip().Name("Tabstrip_#=ReportID#")
         .Items(i =>
         {

         i.Add().Text("Report Details").Selected(true).Content(@<text>


    <div>

    <p> #=HideOnCatalogue#</p>

    Hide from Catalogue?:
     @(Html.Kendo().Switch()
                    .Name("switch_#=ReportID#")
                    .Events(e => e.Change("function(e){ switchChange(e, '#=ReportID#')}"))
        .Checked(#=HideOnCatalogue#)
        .Messages(c => c.Checked("YES").Unchecked("NO"))
        .ToClientTemplate()
    )


    </div>
    </text>);

       



         }).ToClientTemplate())


</script>

How can I bind the value to the switch?  I can display the value in a <p> tag without a problem, as well as passing the report ID to the function called when the switch is clicked.

Thanks

AP
Top achievements
Rank 1
Iron
Iron
Veteran
 asked on 24 Feb 2022
2 answers
97 views

Hi,

I have one table

Emplpyee

..................

Id   Name    Active

1     a                 1

2     b                0

 

my requirement is that

i have one toggle button (by default select Yes(1)) 

based upon that values load grid records

once i change that value to No then display records based upon that

can you please provide me sample code for this one

Yanislav
Telerik team
 answered on 09 Nov 2021
1 answer
109 views

I have multiple switches on a page, each switch has the same class assigned to it.

What i need is that if any switch is checked / changed i need an event to fire and also need to check the state of the remaining switches.

@(Html.Kendo()
    .SwitchFor(a => a.IsAdmin)
    .HtmlAttributes(new { @class = ".permissions" })
    .Messages(c => c.Checked("YES").Unchecked("NO")))

I have tried numerous jquery approaches but none of them even fire when the switch is toggled.


    $('body').on('change', '.permissions', function () {
        // this event handler never gets trigged.....
        // get an instance of each switch and get the toggled / checked state.
        alert();
    });

Patrick
Top achievements
Rank 1
Iron
 answered on 24 Sep 2021
1 answer
300 views
Is there a way I can affect the text color for the checked state of the switch without hacking the theme. through htmlattributes or something like that. I want in in one place not globally.
Petar
Telerik team
 answered on 24 Aug 2021
1 answer
75 views

I have a case where i need to dynamically clone the switch control and use it.
 Im able to clone the switch but the script still refers to the original control .

Tried changing  the id and name properties but still not able to achieve it .

Can anyone let me know how to do it .(FYI im not using mobileswitch)

Thanks in advance.

Anton Mironov
Telerik team
 answered on 12 Aug 2021
2 answers
792 views

First time working with this control and not sure what I'm missing.

Code:

 

                        @(Html.Kendo().SwitchFor(model => model.IsEnabled)
                            .Messages(c => c.Checked("Enabled").Unchecked("Disabled"))
                            )

 

The switch shows up and works, but the true and false message labels do not appear.

 

Responsive
Top achievements
Rank 1
Veteran
 answered on 26 Aug 2020
3 answers
273 views

Hi,

 

Any idea how to reset the theming to another thema (default) ?

 

Currently I'm using the 'material v2' theme

 

Best regards

Dimitar
Telerik team
 answered on 25 Jun 2020
3 answers
243 views

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?

 

 

 

Nikolay
Telerik team
 answered on 28 May 2020
1 answer
274 views

Before version 2019.2 I used MobileSwitch for checkboxes and when I want to clear a form I did this:

1._form.reset();
2.$(_form).find("[type=checkbox]").each(function () {
3.      $("#" + this.id).data("kendoMobileSwitch").refresh();
4.})

 

Now, using Switch, I've changed line 3 to

$("#" + this.id).data("kendoSwitch").refresh();

but that didn't work.

 

How can I achieve the same with new Switch?

Ezequiel
Top achievements
Rank 2
 answered on 09 Sep 2019
Narrow your results
Selected tags
Tags
+? more
Top users last month
horváth
Top achievements
Rank 2
Iron
Iron
Steve
Top achievements
Rank 2
Iron
Erkki
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 2
Iron
Iron
Veteran
Jakub
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
horváth
Top achievements
Rank 2
Iron
Iron
Steve
Top achievements
Rank 2
Iron
Erkki
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 2
Iron
Iron
Veteran
Jakub
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?