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

3 posts, 0 answers
  1. Peter
    Peter avatar
    49 posts
    Member since:
    Jan 2014

    Posted 16 Apr 2014 Link to this post

    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:

    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. Peter
    Peter avatar
    49 posts
    Member since:
    Jan 2014

    Posted 16 Apr 2014 in reply to Peter Link to this post

    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 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");;
  3. Kiril Nikolov
    Kiril Nikolov avatar
    2598 posts

    Posted 17 Apr 2014 Link to this post

    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:

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

    Kiril Nikolov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top