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

Jquery and Kendo Templates

3 Answers 153 Views
Templates
This is a migrated thread and some comments may be shown as answers.
Bill
Top achievements
Rank 1
Bill asked on 29 Sep 2012, 12:05 AM
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?

3 Answers, 1 is accepted

Sort by
0
Brad
Top achievements
Rank 1
answered on 05 Oct 2012, 07:17 PM
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/
0
Bill
Top achievements
Rank 1
answered on 07 Oct 2012, 12:58 AM
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.
0
Brad
Top achievements
Rank 1
answered on 08 Oct 2012, 01:22 PM
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.
Tags
Templates
Asked by
Bill
Top achievements
Rank 1
Answers by
Brad
Top achievements
Rank 1
Bill
Top achievements
Rank 1
Share this question
or