]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/Form.js
8eba470b95502eec782314a2b8511dd08b31ddf4
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 if(!dojo
._hasResource
["dijit.form.Form"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
9 dojo
._hasResource
["dijit.form.Form"] = true;
10 dojo
.provide("dijit.form.Form");
11 dojo
.require("dijit._Widget");
12 dojo
.require("dijit._Templated");
13 dojo
.require("dijit.form._FormMixin");
14 dojo
.require("dijit.layout._ContentPaneResizeMixin");
19 [dijit
._Widget
, dijit
._Templated
, dijit
.form
._FormMixin
, dijit
.layout
._ContentPaneResizeMixin
],
22 // Widget corresponding to HTML form tag, for validation and serialization
25 // | <form dojoType="dijit.form.Form" id="myForm">
26 // | Name: <input type="text" name="name" />
28 // | myObj = {name: "John Doe"};
29 // | dijit.byId('myForm').set('value', myObj);
31 // | myObj=dijit.byId('myForm').get('value');
33 // HTML <FORM> attributes
36 // Name of form for scripting.
40 // Server-side form handler.
44 // HTTP method used to submit the form, either "GET" or "POST".
48 // Encoding type for the form, ex: application/x-www-form-urlencoded.
51 // accept-charset: String?
52 // List of supported charsets.
56 // List of MIME types for file upload.
60 // Target frame for the document to be opened in.
63 templateString
: "<form dojoAttachPoint='containerNode' dojoAttachEvent='onreset:_onReset,onsubmit:_onSubmit' ${!nameAttrSetting}></form>",
65 attributeMap
: dojo
.delegate(dijit
._Widget
.prototype.attributeMap
, {
74 postMixInProperties: function(){
75 // Setup name=foo string to be referenced from the template (but only if a name has been specified)
76 // Unfortunately we can't use attributeMap to set the name due to IE limitations, see #8660
77 this.nameAttrSetting
= this.name
? ("name='" + this.name
+ "'") : "";
78 this.inherited(arguments
);
81 execute: function(/*Object*/ formContents
){
83 // Deprecated: use submit()
88 onExecute: function(){
90 // Deprecated: use onSubmit()
95 _setEncTypeAttr: function(/*String*/ value
){
97 dojo
.attr(this.domNode
, "encType", value
);
98 if(dojo
.isIE
){ this.domNode
.encoding
= value
; }
101 postCreate: function(){
102 // IE tries to hide encType
103 // TODO: remove in 2.0, no longer necessary with data-dojo-params
104 if(dojo
.isIE
&& this.srcNodeRef
&& this.srcNodeRef
.attributes
){
105 var item
= this.srcNodeRef
.attributes
.getNamedItem('encType');
106 if(item
&& !item
.specified
&& (typeof item
.value
== "string")){
107 this.set('encType', item
.value
);
110 this.inherited(arguments
);
113 reset: function(/*Event?*/ e
){
115 // restores all widget values back to their init values,
116 // calls onReset() which can cancel the reset by returning false
118 // create fake event so we can know if preventDefault() is called
120 returnValue
: true, // the IE way
121 preventDefault: function(){ // not IE
122 this.returnValue
= false;
124 stopPropagation: function(){},
125 currentTarget
: e
? e
.target
: this.domNode
,
126 target
: e
? e
.target
: this.domNode
128 // if return value is not exactly false, and haven't called preventDefault(), then reset
129 if(!(this.onReset(faux
) === false) && faux
.returnValue
){
130 this.inherited(arguments
, []);
134 onReset: function(/*Event?*/ e
){
136 // Callback when user resets the form. This method is intended
137 // to be over-ridden. When the `reset` method is called
138 // programmatically, the return value from `onReset` is used
139 // to compute whether or not resetting should proceed
142 return true; // Boolean
145 _onReset: function(e
){
151 _onSubmit: function(e
){
152 var fp
= dijit
.form
.Form
.prototype;
153 // TODO: remove this if statement beginning with 2.0
154 if(this.execute
!= fp
.execute
|| this.onExecute
!= fp
.onExecute
){
155 dojo
.deprecated("dijit.form.Form:execute()/onExecute() are deprecated. Use onSubmit() instead.", "", "2.0");
157 this.execute(this.getValues());
159 if(this.onSubmit(e
) === false){ // only exactly false stops submit
164 onSubmit: function(/*Event?*/ e
){
166 // Callback when user submits the form.
168 // This method is intended to be over-ridden, but by default it checks and
169 // returns the validity of form elements. When the `submit`
170 // method is called programmatically, the return value from
171 // `onSubmit` is used to compute whether or not submission
176 return this.isValid(); // Boolean
181 // programmatically submit form if and only if the `onSubmit` returns true
182 if(!(this.onSubmit() === false)){
183 this.containerNode
.submit();