Have function or expression determine checkbox: data-bind="checked: " value

2 posts, 0 answers
  1. David
    David avatar
    6 posts
    Member since:
    Apr 2016

    Posted 04 Aug Link to this post

    Here is the situation.

    I'm working in a custom editor template for the kendo scheduler.

    I have a model with a string field called "itemType".

     The form fields associated with item type are checkboxes.


    Issue: I want to evaluate whether or not the checkbox should be checked when the editor window is opened.  In order to do this, the most logical thing (in my mind) would be to have some kind of expression to evaluate this.  I tried the following template and I get "Uncaught ReferenceError: Invalid left-hand side in assignment".


    Here is the template:

    1.#for (var i=0; i<itemTypeList.length; i++){#
    2.<input name="itemType" type="checkbox" value="#= itemTypeList[i].Code #" data-type="text" data-bind="checked: itemType=='#= itemTypeList[i].Code #'"> #= itemTypeList[i].Description #
    3.# } #

  2. Stefan
    Stefan avatar
    195 posts

    Posted 08 Aug Link to this post

    Hello David,

    I can assume that the error is caused by this assignment "data-bind="checked: itemType=='#= itemTypeList[i].Code #'". This will not be evaluated to true or false, and will create an incorrect assignment which is causing the error.
    In order to show the checkboxes as checked depending on a specific value, please use the if statement:


    Please check a Dojo example demonstrating this implementation:


    I hope this is helpful.
    Telerik by Progress
    Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.
Back to Top