-- mapes911 <[email protected]> wrote
(on Wednesday, 25 February 2009, 02:08 PM -0800):
> I have created a form that extends Zend_Dojo_Form. I am able to get it to
> show up by creating a controller and an action. 
> 
> Here's my code for the controller UserController.php

<snip> 

> Now, what I'm trying to do is use an xhrGet to load this form within a div
> of another page, and this is when things break down. The form itself shows
> up but it doesn't look like any of the dijit functionality is available.

By default, Zend_Dojo uses programmatic declaration of dijits, which
utilizes JS to parse and instantiate the dijits. This breaks when you
start returning content via XHR that should contain dijits as (1) you're
likely disabling layouts, and thus not getting the necessary JS, and
(2) even if you were returning the JS, Dojo would not be allowed to
execute it (for security purposes).

So, the trick is that when you are returning content to an XHR request,
use _declarative_ dijit generation. You can do that by calling the
following line before you render your form or other dijit view helpers:

    Zend_Dojo_View_Helper_Dojo::setUseDeclarative(true);

Once you have the content on the client side, you then need to run the
node containing the new content through dojo.parser.parse(). So, for
example, say you injected it into a node with id "ajaxContent", you
would do this:

    dojo.parser.parse("ajaxContent");

and be all set. That line can go right in your XHR load callback, btw,
right after you insert the content into the DOM.

Some widgets, such as ContentPane, will let you fetch the content and
then do the parsing for you as well.

I highly recommend that if you are going to ever be returning content
via XHR when using Dojo to just use declarative markup generation. It
will simplify things for you, and you will gain a lot of automation.


> I am guessing this has to do with the way I am loading dojo, but I can't
> seem to find the answers.
> 
> Have any of you guys out there tried to do anything like this? My main page
> (which contains the div) uses a layout in which dojo is enabled. The
> editinfo page uses a different layout which also loads dojo (i know this is
> wrong but i did that to test that i was actually doing the form stuff
> right). What I don't know is what the right way is to load this form using
> an xhrGet call and have it actually have dijit functionality working.
> 
> This is the code I'm using to load the page within my div
> 
> Code:
> 
>       // let's call the ajax url now so we can update the page 
>       dojo.xhrGet( {
>         // The following URL must match that used to test the server.
>         url: ajaxurl, 
>         handleAs: "text",
> 
>         timeout: 5000, // Time in milliseconds
> 
>         // The LOAD function will be called on a successful response.
>         load: function(response, ioArgs) {
>           dojo.byId("profileContent").innerHTML = response; 
>           return response;
>         },
> 
>         // The ERROR function will be called in an error case.
>         error: function(response, ioArgs) { 
>           console.error("HTTP status code: ", ioArgs.xhr.status); 
>           return response; 
>         }
>     });
> 
> I hope that makes sense.. anyone have any ideas that could help me?
> Do I need to disable layouts on the editinfo stuff? If so, how do I make
> sure that the dijit stuff will work? Help!! 

-- 
Matthew Weier O'Phinney
Software Architect       | [email protected]
Zend Framework           | http://framework.zend.com/

Reply via email to