On Thu, Jan 8, 2009 at 5:50 PM, Matthew Weier O'Phinney <matt...@zend.com> wrote: > On Thursday 08 January 2009 12:22:31 Mustafa A. Hashmi wrote: >> I am in the process of switching our application to make use of dojo >> forms, however, am having some issues with forms which are rendered >> via xhr requests. In a nutshell: >> >> a) Layout is rendered and the index action renders a dojo form which >> works perfectly fine. >> b) After submitting the form, the user manually follows a link which >> calls a JS function and loads the required action template in a >> specified div. >> c) The loaded dojo form in the resulting div however doesn't seem to >> be 'dojo enabled'. The form does render, albeit without any styles or >> dijit functionality. > > When using XHR to retrieve (X)HTML content that will be injected into > the DOM, you need to do two things: > > 1) Any dojo modules that the new content uses must already be loaded > (i.e., the dojo.require calls should already have occurred). > Because of how Zend_Dojo works, anything aggregated in the dojo > view helper will not be sent in the payload (unless you explicitly > include it). Additionally, HTML content pulled by XHR ignores any > <script>s attached -- which means even if you did return the dojo > view helper payload, it wouldn't be executed. So your initial > payload must have all the requisite dojo.require statements.
As you demonstrate in your pastebin app, I too am gearing the app for a light js library build, hence all required modules that the app needs are specified explicitly for loading. The front controller is initialized with the installer module plugin which instantiates the view and sets required modules / paths / view helpers, etc. dojo.provide("installer.layer"); (function() { dojo.require("dijit.layout.ContentPane"); dojo.require("dijit.layout.BorderContainer"); ... > For this reason, it's also best to turn on declarative markup for > any XHR payloads -- since the programmatic elements will not be > present. You can do this with the following: > > Zend_Dojo_View_Helper_Dojo::setUseDeclarative(true); Also done during front controller initialization of the view obj. > 2) You need to run the dojo parser over the returned content. If > you're pulling the content into a ContentPane, you can do this by > setting the "parseOnLoad" property of that pane to true. Otherwise, > make sure you have the dojo.parser module loaded, and call: > > dojo.parser.parse(<dom node containing retrieved content>); I was doing every one of the things you recommended, barring the dojo.parser.parse bit. Once the response is injected into the relevant dom node, I simply ran the parser over said node and everything came alive. Thank you Matthew, much appreciated! -- Mustafa A. Hashmi