| 1 |
define([ |
| 2 |
"dojo/_base/lang", |
| 3 |
"dojo/_base/kernel", |
| 4 |
"dojo/_base/event", |
| 5 |
"dojo/window", |
| 6 |
"./_Mixin", |
| 7 |
"dojo/_base/declare" |
| 8 |
], function(lang, dojo, event, windowUtils, _Mixin, declare){ |
| 9 |
var fm = lang.getObject("dojox.form.manager", true), |
| 10 |
aa = fm.actionAdapter; |
| 11 |
|
| 12 |
return declare("dojox.form.manager._FormMixin", null, { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
name: "", |
| 23 |
action: "", |
| 24 |
method: "", |
| 25 |
encType: "", |
| 26 |
"accept-charset": "", |
| 27 |
accept: "", |
| 28 |
target: "", |
| 29 |
|
| 30 |
startup: function(){ |
| 31 |
this.isForm = this.domNode.tagName.toLowerCase() == "form"; |
| 32 |
if(this.isForm){ |
| 33 |
this.connect(this.domNode, "onreset", "_onReset"); |
| 34 |
this.connect(this.domNode, "onsubmit", "_onSubmit"); |
| 35 |
} |
| 36 |
this.inherited(arguments); |
| 37 |
}, |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
_onReset: function(evt){ |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
var faux = { |
| 47 |
returnValue: true, |
| 48 |
preventDefault: function(){ |
| 49 |
this.returnValue = false; |
| 50 |
}, |
| 51 |
stopPropagation: function(){}, currentTarget: evt.currentTarget, target: evt.target |
| 52 |
}; |
| 53 |
|
| 54 |
if(!(this.onReset(faux) === false) && faux.returnValue){ |
| 55 |
this.reset(); |
| 56 |
} |
| 57 |
event.stop(evt); |
| 58 |
return false; |
| 59 |
}, |
| 60 |
|
| 61 |
onReset: function(){ |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
return true; |
| 68 |
}, |
| 69 |
|
| 70 |
reset: function(){ |
| 71 |
|
| 72 |
|
| 73 |
this.inspectFormWidgets(aa(function(_, widget){ |
| 74 |
if(widget.reset){ |
| 75 |
widget.reset(); |
| 76 |
} |
| 77 |
})); |
| 78 |
if(this.isForm){ |
| 79 |
this.domNode.reset(); |
| 80 |
} |
| 81 |
return this; |
| 82 |
}, |
| 83 |
|
| 84 |
_onSubmit: function(evt){ |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
if(this.onSubmit(evt) === false){ |
| 89 |
event.stop(evt); |
| 90 |
} |
| 91 |
}, |
| 92 |
|
| 93 |
onSubmit: function(){ |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
return this.isValid(); |
| 103 |
}, |
| 104 |
|
| 105 |
submit: function(){ |
| 106 |
|
| 107 |
|
| 108 |
if(this.isForm){ |
| 109 |
if(!(this.onSubmit() === false)){ |
| 110 |
this.domNode.submit(); |
| 111 |
} |
| 112 |
} |
| 113 |
}, |
| 114 |
|
| 115 |
isValid: function(){ |
| 116 |
|
| 117 |
|
| 118 |
for(var name in this.formWidgets){ |
| 119 |
var stop = false; |
| 120 |
aa(function(_, widget){ |
| 121 |
if(!widget.get("disabled") && widget.isValid && !widget.isValid()){ |
| 122 |
stop = true; |
| 123 |
} |
| 124 |
}).call(this, null, this.formWidgets[name].widget); |
| 125 |
if(stop){ |
| 126 |
return false; |
| 127 |
} |
| 128 |
} |
| 129 |
return true; |
| 130 |
}, |
| 131 |
validate: function(){ |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
var isValid = true, |
| 138 |
formWidgets = this.formWidgets, |
| 139 |
didFocus = false, name; |
| 140 |
|
| 141 |
for(name in formWidgets){ |
| 142 |
aa(function(_, widget){ |
| 143 |
|
| 144 |
|
| 145 |
widget._hasBeenBlurred = true; |
| 146 |
var valid = widget.disabled || !widget.validate || widget.validate(); |
| 147 |
if(!valid && !didFocus){ |
| 148 |
|
| 149 |
windowUtils.scrollIntoView(widget.containerNode || widget.domNode); |
| 150 |
widget.focus(); |
| 151 |
didFocus = true; |
| 152 |
} |
| 153 |
isValid = isValid && valid; |
| 154 |
}).call(this, null, formWidgets[name].widget); |
| 155 |
} |
| 156 |
|
| 157 |
return isValid; |
| 158 |
} |
| 159 |
}); |
| 160 |
}); |