How to make a Dojo dijit form programmatically

Jmsegrev picture Jmsegrev · Oct 13, 2011 · Viewed 12.4k times · Source

Im new to Dojo and im trying to make some ui, but only using the programmatic way.

I would like if someone could show me some example of how to make a form programmarically using Dojo dijit.form.Form. I've been looking for some example but all i can find is the declarative way of it.

Answer

jglatre picture jglatre · Feb 19, 2012

A more object oriented solution:

define( [
"dojo/_base/declare", 
"dijit/form/Form",
"dijit/form/Textarea",
"dijit/form/Button"
],

function(declare, Form, TextArea, Button) {
    return declare( "mypackage.MyForm", Form, {
        textarea: new TextArea({}),

        submitButton: new Button({
            type: "submit",
            label: "ready!"
        }),

        constructor: function(args) {
            declare.safeMixin(this, args);
        },

        onSubmit: function() { 
            alert(this.textarea.get('value')); 
        },

        postCreate: function() {
            this.domNode.appendChild( this.textarea.domNode );
            this.domNode.appendChild( this.submitButton.domNode );
        }
    });
}
);

Just drop a new mypackage.MyForm({}) at any place you might expect a widget.