I am trying to do a simple task. This task is to load a HTML containg dijit.Form into a ContentPane. I don’t know which dijits I will need before I load this HTML, but the loaded HTML will contain applicable require‘s to load them.
So in order to be able to execute the script from loaded HTML I use dojox.layout.ContentPane. However when I set parseOnLoad to true, the parsing takes place before the script execution, so the dijits aren’t available when first loading the content. Also when I try to use onDownloadEnd callback, when this callback is run, the dijits from require‘s are still not loaded.
Only thing I can think of myself is using setTimeout to defer parsing to a time when these scripts will be executed. I don’t like this solution however as it may fail from time to time and it would make the application less responsible.
So how should I perform the parsing so that it happens right after the require statement from loaded HTML is run?
I can see two possible solutions – both with
dijit/layout/ContentPane:Use Dojo 1.8.0, as the parser supports auto require, it will load dependencies itself as you can see here: http://jsfiddle.net/phusick/vr4h4/
Put the list of dependencies somewhere into your form template, e.g. in
data-configattribute of yourdijit/form/Form:Set
parseOnLoad:falsefor thedijit/layout/ContentPane, load the template, get the list of dependencies,requirethem and then in the factory functionparser.parse()containerNodeof yourContentPane(see it in action http://jsfiddle.net/phusick/QA4gH/):EDIT: I just got this idea that writing an auto require (for Dojo <1.8) is just about adding a short
getDependencies()method, so you don’t need to list dependencies as I mentioned in the second option above:See it working at jsFiddle: http://jsfiddle.net/phusick/hnjWt/