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

The init event must be called "onInit" or it won't work. Intentional?

2 Answers 90 Views
Drawer (Mobile)
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 17 Apr 2014, 02:39 AM
I declared my Drawer like this
<div id="app-drawer" data-role="drawer" data-init="drawerInit">

With a function in script tags like:
function drawerInit(e) {...}

As per the documentation: http://docs.telerik.com/kendo-ui/api/mobile/drawer

But it doesn't fire... 
I renamed my function "drawerInit" to "onInit" and it now works!

Why wouldn't it just call the function specified in the data-init attribute?
Is this a bug or intentional?

2 Answers, 1 is accepted

Sort by
0
Peter
Top achievements
Rank 1
answered on 17 Apr 2014, 02:44 AM
Sorry to add to this.

But I wanted to use the onInit method to call show() on the Drawer, so it would start by showing.
But this won't work, apparently the Drawer isn't actually initialized at the time of onInit being called because the "kendoMobileDrawer" method below returns undefined.
I'm confused, what purpose is the onInit serving, if I can't do this?
It does work if I put a 1 second timer before calling drawer.show() so you can know that the #app-drawer ID I'm using etc, is correct.
But I don't want to use a timer as it's unreliable, that's why I found this init() event....

function onInit(e) {
console.log("drawInit", e);
var drawer = $("#app-drawer").data("kendoMobileDrawer");
drawer.show();
}
0
Kiril Nikolov
Telerik team
answered on 17 Apr 2014, 11:16 AM
Hi Peter,

The init event is fired when the widget starts its initialization, and not when the initialization is finished, so this is why you cannot open the drawer in the init event as it is not yet initialized. You can do the same using setTimeout() just to make sure that the open action is called when the init is finished. Please check the following example:

http://jsbin.com/zejib/1/edit

Note that you do not need to specify a timeout of 1000ms.

Regards,
Kiril Nikolov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Drawer (Mobile)
Asked by
Peter
Top achievements
Rank 1
Answers by
Peter
Top achievements
Rank 1
Kiril Nikolov
Telerik team
Share this question
or