Login Register

Creating widgets programmatically

Hello

I started using dojo whith 0.4, I used to make some ajax calls returning html with a lot of dojo widgets in this code, later I just used to call createWidget for every one and done ....

now I have a big problem in 1.1 ... is there any way to convert the returned html in widgets like I used to in 0.4?

Thanks in advance for your help

Adrian

you can place the returned

you can place the returned html in some dom node, and call dojo.parser.parse(thatDomNode), or you can simply create the widgets using nodes reffed in the html:

dojo.xhrGet({
    url:"snippet.html", // has a <div class='bar'></div> somewhere
    load:function(data){
        dojo.byId("somewhere").innerHTML = data;
        dojo.query(".bar","somewhere").forEach(function(n){
             new dijit.form.Button({},n);
        });
    }
});

the parser was is easier, imho.

Thank you very much... you

Thank you very much... you helped me a lot with your answer

cannot create a

cannot create a by-me-declared widget.

i have a following declaration:

<div dojoType="dijit.Declaration"
widgetClass="TextField" defaults="{defaultText:''}">
<input type="text" dojoAttachPoint="tNode" value="${defaultText}"/>
</div>

how can i create the dinget programmaticaly?

using:

var w1=new TextField(defaultText="test");

throws an esception:

"TextField is not defined"

what can i do?

please help!

thank you in advance!