1 define("dijit/form/_FormValueMixin", [
2 "dojo/_base/declare", // declare
3 "dojo/dom-attr", // domAttr.set
4 "dojo/keys", // keys.ESCAPE
5 "dojo/sniff", // has("ie"), has("quirks")
7 ], function(declare, domAttr, keys, has, _FormWidgetMixin){
10 // dijit/form/_FormValueMixin
12 return declare("dijit.form._FormValueMixin", _FormWidgetMixin, {
14 // Mixin for widgets corresponding to native HTML elements such as `<input>` or `<select>`
15 // that have user changeable values.
17 // Each _FormValueMixin represents a single input value, and has a (possibly hidden) `<input>` element,
18 // to which it serializes it's input value, so that form submission (either normal submission or via FormBind?)
22 // Should this widget respond to user input?
23 // In markup, this is specified as "readOnly".
24 // Similar to disabled except readOnly form values are submitted.
27 _setReadOnlyAttr: function(/*Boolean*/ value){
28 domAttr.set(this.focusNode, 'readOnly', value);
29 this._set("readOnly", value);
32 postCreate: function(){
33 this.inherited(arguments);
35 if(has("ie")){ // IE won't stop the event with keypress
36 this.connect(this.focusNode || this.domNode, "onkeydown", this._onKeyDown);
38 // Update our reset value if it hasn't yet been set (because this.set()
39 // is only called when there *is* a value)
40 if(this._resetValue === undefined){
41 this._lastValueReported = this._resetValue = this.value;
45 _setValueAttr: function(/*anything*/ newValue, /*Boolean?*/ priorityChange){
47 // Hook so set('value', value) works.
49 // Sets the value of the widget.
50 // If the value has changed, then fire onChange event, unless priorityChange
51 // is specified as null (or false?)
52 this._handleOnChange(newValue, priorityChange);
55 _handleOnChange: function(/*anything*/ newValue, /*Boolean?*/ priorityChange){
57 // Called when the value of the widget has changed. Saves the new value in this.value,
58 // and calls onChange() if appropriate. See _FormWidget._handleOnChange() for details.
59 this._set("value", newValue);
60 this.inherited(arguments);
65 // Restore the value to the last value passed to onChange
66 this._setValueAttr(this._lastValueReported, false);
71 // Reset the widget's value to what it was at initialization time
72 this._hasBeenBlurred = false;
73 this._setValueAttr(this._resetValue, true);
76 _onKeyDown: function(e){
77 if(e.keyCode == keys.ESCAPE && !(e.ctrlKey || e.altKey || e.metaKey)){
78 if(has("ie") < 9 || (has("ie") && has("quirks"))){
79 e.preventDefault(); // default behavior needs to be stopped here since keypress is too late
80 var node = e.srcElement,
81 te = node.ownerDocument.createEventObject();
82 te.keyCode = keys.ESCAPE;
83 te.shiftKey = e.shiftKey;
84 node.fireEvent('onkeypress', te);