Jquery and Kendo Templates

4 posts, 0 answers
  1. Bill
    Bill avatar
    13 posts
    Member since:
    Jul 2012

    Posted 28 Sep 2012 Link to this post

    There is sometimes a problem getting Jquery to work with DOM elements that are created from a Kendo template, The following jsfiddle example illustrates my problem: http://jsfiddle.net/billmcknight/G2Xr2/   I can get Jquery to find and fill a textbox when the dom is not created thru a Kendo template but not when it is.  By all rights the Jquery function should work the same way, one would think, but when  jquery looks here for a template-based input, it can't find it and update it.   There are probably ViewModel ways to do this, but I am wondering what is the right way to make Jquery behave correctly?
  2. Brad
    Brad avatar
    2 posts
    Member since:
    Oct 2012

    Posted 05 Oct 2012 Link to this post

    It seems that KendoUI is re-initializing the template item after your click function runs, but before display is rendered. I've updated your example to update the ViewModel (if needed) and this seems to work. Uncomment a section in the following jsfiddle for demonstration: http://jsfiddle.net/G2Xr2/20/
  3. Kendo UI is VS 2017 Ready
  4. Bill
    Bill avatar
    13 posts
    Member since:
    Jul 2012

    Posted 06 Oct 2012 Link to this post

    Thanks Brad for taking a look at this.  I think you are suggesting the easiest and most effective way to go is to do an update of the viewmodel value, and not try using Jquery to change values for widgets which come from a template bound to a viewmodel.   I am still not satisfied that I completely understand what is going on here.  Consider this further variant to our jsfiddle examples: http://jsfiddle.net/billmcknight/CH3fW/
    It seems to suggest that a jquery change to a textbox value bound to a viewmodel is possible though not always.   Of course the jsfiddle examples here are simplifications of the actual situation I am trying to solve, and I am not yet sure that I will be able to do everything thru a viewmodel methods.
  5. Brad
    Brad avatar
    2 posts
    Member since:
    Oct 2012

    Posted 08 Oct 2012 Link to this post

    I'm just beginning to learn Kendo UI myself, so I won't pretend to be an expert. It seems logical though, that since the input value is bound to the viewmodel, that the corresponding viewmodel variable must be changed in order to persist. This explains why the value changes back to the original value (the myInputText variable hasn't changed from its initial value).

    I guess I'm not exactly clear - if you don't want to update the viewModel variables, is there a reason for binding to them? If there is a reason for binding to a viewModel, then perhaps you are suggesting that changing the value of an input via JavaScript should update the viewModel automatically (as if it were typed in). If so, I can't speak as to why that may be the case but imagine it would have to do with the binding of events by kendo for the template functionality.

    I don't have time to look further into it, but would be interested in the outcome.
Back to Top
Kendo UI is VS 2017 Ready