summaryrefslogtreecommitdiff
path: root/lib/dijit/form/Form.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dijit/form/Form.js')
-rw-r--r--lib/dijit/form/Form.js231
1 files changed, 178 insertions, 53 deletions
diff --git a/lib/dijit/form/Form.js b/lib/dijit/form/Form.js
index 618700b5d..8eba470b9 100644
--- a/lib/dijit/form/Form.js
+++ b/lib/dijit/form/Form.js
@@ -1,64 +1,189 @@
/*
- Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
-if(!dojo._hasResource["dijit.form.Form"]){
-dojo._hasResource["dijit.form.Form"]=true;
+if(!dojo._hasResource["dijit.form.Form"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dijit.form.Form"] = true;
dojo.provide("dijit.form.Form");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("dijit.form._FormMixin");
-dojo.declare("dijit.form.Form",[dijit._Widget,dijit._Templated,dijit.form._FormMixin],{name:"",action:"",method:"",encType:"","accept-charset":"",accept:"",target:"",templateString:"<form dojoAttachPoint='containerNode' dojoAttachEvent='onreset:_onReset,onsubmit:_onSubmit' ${!nameAttrSetting}></form>",attributeMap:dojo.delegate(dijit._Widget.prototype.attributeMap,{action:"",method:"",encType:"","accept-charset":"",accept:"",target:""}),postMixInProperties:function(){
-this.nameAttrSetting=this.name?("name='"+this.name+"'"):"";
-this.inherited(arguments);
-},execute:function(_1){
-},onExecute:function(){
-},_setEncTypeAttr:function(_2){
-this.encType=_2;
-dojo.attr(this.domNode,"encType",_2);
-if(dojo.isIE){
-this.domNode.encoding=_2;
-}
-},postCreate:function(){
-if(dojo.isIE&&this.srcNodeRef&&this.srcNodeRef.attributes){
-var _3=this.srcNodeRef.attributes.getNamedItem("encType");
-if(_3&&!_3.specified&&(typeof _3.value=="string")){
-this.set("encType",_3.value);
-}
-}
-this.inherited(arguments);
-},reset:function(e){
-var _4={returnValue:true,preventDefault:function(){
-this.returnValue=false;
-},stopPropagation:function(){
-},currentTarget:e?e.target:this.domNode,target:e?e.target:this.domNode};
-if(!(this.onReset(_4)===false)&&_4.returnValue){
-this.inherited(arguments,[]);
-}
-},onReset:function(e){
-return true;
-},_onReset:function(e){
-this.reset(e);
-dojo.stopEvent(e);
-return false;
-},_onSubmit:function(e){
-var fp=dijit.form.Form.prototype;
-if(this.execute!=fp.execute||this.onExecute!=fp.onExecute){
-dojo.deprecated("dijit.form.Form:execute()/onExecute() are deprecated. Use onSubmit() instead.","","2.0");
-this.onExecute();
-this.execute(this.getValues());
-}
-if(this.onSubmit(e)===false){
-dojo.stopEvent(e);
-}
-},onSubmit:function(e){
-return this.isValid();
-},submit:function(){
-if(!(this.onSubmit()===false)){
-this.containerNode.submit();
-}
-}});
+dojo.require("dijit.layout._ContentPaneResizeMixin");
+
+
+dojo.declare(
+ "dijit.form.Form",
+ [dijit._Widget, dijit._Templated, dijit.form._FormMixin, dijit.layout._ContentPaneResizeMixin],
+ {
+ // summary:
+ // Widget corresponding to HTML form tag, for validation and serialization
+ //
+ // example:
+ // | <form dojoType="dijit.form.Form" id="myForm">
+ // | Name: <input type="text" name="name" />
+ // | </form>
+ // | myObj = {name: "John Doe"};
+ // | dijit.byId('myForm').set('value', myObj);
+ // |
+ // | myObj=dijit.byId('myForm').get('value');
+
+ // HTML <FORM> attributes
+
+ // name: String?
+ // Name of form for scripting.
+ name: "",
+
+ // action: String?
+ // Server-side form handler.
+ action: "",
+
+ // method: String?
+ // HTTP method used to submit the form, either "GET" or "POST".
+ method: "",
+
+ // encType: String?
+ // Encoding type for the form, ex: application/x-www-form-urlencoded.
+ encType: "",
+
+ // accept-charset: String?
+ // List of supported charsets.
+ "accept-charset": "",
+
+ // accept: String?
+ // List of MIME types for file upload.
+ accept: "",
+
+ // target: String?
+ // Target frame for the document to be opened in.
+ target: "",
+
+ templateString: "<form dojoAttachPoint='containerNode' dojoAttachEvent='onreset:_onReset,onsubmit:_onSubmit' ${!nameAttrSetting}></form>",
+
+ attributeMap: dojo.delegate(dijit._Widget.prototype.attributeMap, {
+ action: "",
+ method: "",
+ encType: "",
+ "accept-charset": "",
+ accept: "",
+ target: ""
+ }),
+
+ postMixInProperties: function(){
+ // Setup name=foo string to be referenced from the template (but only if a name has been specified)
+ // Unfortunately we can't use attributeMap to set the name due to IE limitations, see #8660
+ this.nameAttrSetting = this.name ? ("name='" + this.name + "'") : "";
+ this.inherited(arguments);
+ },
+
+ execute: function(/*Object*/ formContents){
+ // summary:
+ // Deprecated: use submit()
+ // tags:
+ // deprecated
+ },
+
+ onExecute: function(){
+ // summary:
+ // Deprecated: use onSubmit()
+ // tags:
+ // deprecated
+ },
+
+ _setEncTypeAttr: function(/*String*/ value){
+ this.encType = value;
+ dojo.attr(this.domNode, "encType", value);
+ if(dojo.isIE){ this.domNode.encoding = value; }
+ },
+
+ postCreate: function(){
+ // IE tries to hide encType
+ // TODO: remove in 2.0, no longer necessary with data-dojo-params
+ if(dojo.isIE && this.srcNodeRef && this.srcNodeRef.attributes){
+ var item = this.srcNodeRef.attributes.getNamedItem('encType');
+ if(item && !item.specified && (typeof item.value == "string")){
+ this.set('encType', item.value);
+ }
+ }
+ this.inherited(arguments);
+ },
+
+ reset: function(/*Event?*/ e){
+ // summary:
+ // restores all widget values back to their init values,
+ // calls onReset() which can cancel the reset by returning false
+
+ // create fake event so we can know if preventDefault() is called
+ var faux = {
+ returnValue: true, // the IE way
+ preventDefault: function(){ // not IE
+ this.returnValue = false;
+ },
+ stopPropagation: function(){},
+ currentTarget: e ? e.target : this.domNode,
+ target: e ? e.target : this.domNode
+ };
+ // if return value is not exactly false, and haven't called preventDefault(), then reset
+ if(!(this.onReset(faux) === false) && faux.returnValue){
+ this.inherited(arguments, []);
+ }
+ },
+
+ onReset: function(/*Event?*/ e){
+ // summary:
+ // Callback when user resets the form. This method is intended
+ // to be over-ridden. When the `reset` method is called
+ // programmatically, the return value from `onReset` is used
+ // to compute whether or not resetting should proceed
+ // tags:
+ // callback
+ return true; // Boolean
+ },
+
+ _onReset: function(e){
+ this.reset(e);
+ dojo.stopEvent(e);
+ return false;
+ },
+
+ _onSubmit: function(e){
+ var fp = dijit.form.Form.prototype;
+ // TODO: remove this if statement beginning with 2.0
+ if(this.execute != fp.execute || this.onExecute != fp.onExecute){
+ dojo.deprecated("dijit.form.Form:execute()/onExecute() are deprecated. Use onSubmit() instead.", "", "2.0");
+ this.onExecute();
+ this.execute(this.getValues());
+ }
+ if(this.onSubmit(e) === false){ // only exactly false stops submit
+ dojo.stopEvent(e);
+ }
+ },
+
+ onSubmit: function(/*Event?*/ e){
+ // summary:
+ // Callback when user submits the form.
+ // description:
+ // This method is intended to be over-ridden, but by default it checks and
+ // returns the validity of form elements. When the `submit`
+ // method is called programmatically, the return value from
+ // `onSubmit` is used to compute whether or not submission
+ // should proceed
+ // tags:
+ // extension
+
+ return this.isValid(); // Boolean
+ },
+
+ submit: function(){
+ // summary:
+ // programmatically submit form if and only if the `onSubmit` returns true
+ if(!(this.onSubmit() === false)){
+ this.containerNode.submit();
+ }
+ }
+ }
+);
+
}