Zend Framework, lazy-loaded Dojo Tabs and Javascript

12
Jan

Here's a quick tip that might save a few of you some time out there. When lazy loading tabs in Dojo + Zend Framework, because the content is retrieved via AJAX, you aren't able to just embed Javascript in the page you're fetching and have it work, nor can you apply any onLoad functions at application start, because the pages have not been instantiated. The way around this is to use the onLoad function of the contentPane view helper:

<?php ( $this->contentPane(
   
'tab-name',
   
'',
    array(
'title' => 'Demonstration Tab',
       
'class' => 'tab',
       
'href' => $this->url(
            array(   
'controller' => 'controllername',
                      
'action' => 'list',
                      
'format' => 'ajax'
                   
),
                   
'default',
                   
false ),
             
'parseOnLoad' => true,
       
'onLoad' => 'loadTabCode();',
    ));
?>


Simply include any code you wish to execute in your loadTabCode() function (or indeed just define it right there in the view helper), and it'll work just fine! This wasn't documented anywhere obvious for me, and it was a mere fluke I stumbed upon how to do it, so I hope this saves someone else a lot of head scratching too.

Comments

Thanks for this wonderful post. Admiring the time and effort you put into your blog and detailed information you offer.

Amazing! This is really a big help for us beginners.

Post new comment

The content of this field is kept private and will not be shown publicly.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.