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

Dynamically added buttons not recognized

1 Answer 17 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nathaniel
Top achievements
Rank 1
Nathaniel asked on 18 Jun 2015, 07:57 PM

When one of my views is loaded, I make an AJAX call with data-init and then dynamically create div elements with some <span>text</span> inside. The divs have data-role="button" and data-click="myFunction". When I test the template on another page (not created dynamically) everything works great. But when dynamically added, the buttons are not recognized as buttons and myFunction doesn't fire.

Note, I am not using kendo templating to add the divs, I am using .append('with my html in here').

How can I dynamically add button and still have them recognized?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 23 Jun 2015, 08:16 AM
Hello Nathaniel,

This is expected behavior, since the Kendo UI initalization logic has already passed at the time you insert your HTML into the page.

You can use the kendo.init method to trigger Kendo UI to instantiate all dynamically loaded widgets. You need to pass the id of the element that contains the buttons, as well as kendo.mobile.ui namespace as a second parameter:

kendo.init($("#container-element-id"), kendo.mobile.ui);


Regards,
Tsvetina
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
General Discussion
Asked by
Nathaniel
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or