views:

17

answers:

0

Hi stackers,

I want to get the action to output the necessary javascript for initializing the dijits in the Zend_Dojo_Form. When I have layouts enabled, it works. I want to disable layouts because this is an ajax response.

With layouts enabled, I get a lot of javascript inserted into the header for initializing the Zend_Dojo_Form. For example:

dojo.addOnLoad(function() { var form = zend.findParentForm ...
var zendDijits = [{ ...

I'm sure you know what I mean.

The problem is that I'd rather not use declarative markup for the Zend_Dojo_Form. So I need to echo that javascript.

How can I get it? Any ideas? If you need to see some code...

I had this, when I realized my problem of no javascript:

public function processxAction()
{
    $this->_helper->viewRenderer->setNoRender();
    $this->_helper->layout->disableLayout();
    //Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
    $request = $this->getRequest();
    $this->_helper->ajaxContext->initContext();
    if ($request->isXmlHttpRequest())
    {
        $postdata = $request->getPost();
        if ($postdata['type'])
        {
            $form = new Form_Notification();
            echo $form->getSubForm('step2');
        }
    }
}

So I tried this:

public function processxAction()
{
    //$this->_helper->viewRenderer->setNoRender();
    $this->_helper->layout->disableLayout();
    //Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
    $request = $this->getRequest();
    $this->_helper->ajaxContext->initContext();
    if ($request->isXmlHttpRequest())
    {
        $postdata = $request->getPost();
        if ($postdata['type'])
        {
            Zend_Dojo::enableView($this->view);
            $form = new Form_Notification();
            $subform = $form->getSubForm('step2');
            Zend_Dojo::enableForm($subform);
            $this->view->subform = $subform;
        }
    }
}

I'm not really sure what I'm doing with that Zend_Dojo::enableView and Zend_Dojo::enableForm, but it doesn't work. In my view I had:

echo $this->dojo();
echo $this->subform;

I'm sure other people have done this. There is probably something pretty simple and automatic, and I'm going about inside out.

UPDATE:

I've had a look at the javascript that is generated for initializing the dijits. The problem is it uses dojo.addOnLoad. So that would be useless for an ajax call anyway.

So I guess I've really to ask, what is the clean way of doing this? Does Zend Framework not have a way to initialize Zend_Dojo_Form elements for use with ajax calls?