How to make a Dojo dijit programming form

Im new for Dojo and im trying to do some ui, but only with a programmatic way.

I would like someone to show me an example of how to make a form programmatically using Dojo dijit.form.Form. I was looking for some example, but all I can find is a declarative way of it.

+8
source share
2 answers

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 release new mypackage.MyForm({}) anywhere you can expect a widget.

+8
source share

Its pretty straightforward. You simply create all the parts of the form and then add all the parts to their respective parents. To create form objects like any dijit object, you pass a param and domNode object to the constructor to place it, for example:

 var resetbtn = new dijit.form.Button({ type: 'reset', label: 'Reset' }, dojo.doc.createElement('button')); 

Full example here . To find out what properties you can add to a params object, see the Docs API . Any of the properties can be added to the parameter list.

+6
source share

All Articles