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

Click bind in a nested template doesn't work properly

1 Answer 344 Views
Templates
This is a migrated thread and some comments may be shown as answers.
leboart
Top achievements
Rank 1
leboart asked on 29 Mar 2013, 01:24 AM
Hi All,
I have the next to two pieces of code:
<div id="application">
     
</div>
<script type="text/x-kendo-template" id="application-layout">      
     <div id="command-bar" data-bind="source:this" data-template="command-bar-template">  </div>       
</script>  
<script type="text/x-kendo-template" id="command-bar-template">
      <button id="nextButton" class="k-button barButton" data-bind="click: next">Next</button>
      <button id="backButton" class="k-button barButton" data-bind="click: back">Back</button>
</script>
and this:
var appViewModel = kendo.observable({
 
    next: function()
    
      console.log("next pushed");
    },
    back: function()
    {
       console.log("back pushed");
    }
});
 
var appLayout = new kendo.Layout("application-layout", {model: appViewModel});
appLayout.render("#application");
The thing is that only works (in this case ) the next button (It prints "next pushed" in the console). So , I say  in this case , because  when I put the "<button id="backButton"..."  first in the "command-bar-template", then  only works the back button. What am I doing wrong?. Here is the jsbin: http://jsbin.com/edamuj/631

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 01 Apr 2013, 01:48 PM
Hello leboart,

The problem is that #command-bar-template does not have a root element. To avoid the issue please wrap the buttons inside a tag, for example div.
<script type="text/x-kendo-template" id="command-bar-template">
  <div>
     <button id="nextButton" data-bind="click: next">Next</button>
     <button id="backButton" data-bind="click: back">Back</button>
  </div>
</script>

For your convenience I updated the jsBin sample: http://jsbin.com/edamuj/640/edit
I hope this will help. 

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Templates
Asked by
leboart
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or