Can this template be improved? (Conditional)

2 posts, 0 answers
  1. Kjell
    Kjell avatar
    281 posts
    Member since:
    Jun 2010

    Posted 11 Jan Link to this post

    The template below works but it seems kind of goofy.  Is there a better way to set the "Checked" value conditionally?

    I can do it easily with a plain checkbox but I prefer to use the Kendo one for the styling.

     

    <script type="text/x-kendo-tmpl" id="connectorTemplate">
         <div class="tabOption">
             # if (Selected) { # 
     
             @(Html.Kendo().CheckBox()
                     .Name("#:Id#")
                     .Checked(true)
             )
     
             # } else { #
     
             @(Html.Kendo().CheckBox()
                     .Name("#:Id#")
                     .Checked(false)
             )
     
             # } #
     
             <span>#:Name# </span>
         </div>
     </script>
  2. Stamo Gochev
    Admin
    Stamo Gochev avatar
    165 posts

    Posted 13 Jan Link to this post

    Hi Kjell,

    I think that you can place the Selected condition in the Checked property of the checkbox (similar to what you have done with the Id) and use the ternary operator. The following thread can be used as a reference:

    http://stackoverflow.com/a/11040193

    Regards,
    Stamo Gochev
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top