diff options
author | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
---|---|---|
committer | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
commit | 7c97d17aaf373339a8bcd917ad59ca6018148f0d (patch) | |
tree | 5a3c04f0f9529be392c1263d3feb75806eb43797 /lib/dijit/form/_FormValueMixin.js.uncompressed.js | |
parent | 70db7424e7068701e60cc5bcdfe8f858be508179 (diff) | |
parent | c670a80ddd9b03bd4ea6d940a9ed682fd26248d7 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'lib/dijit/form/_FormValueMixin.js.uncompressed.js')
-rw-r--r-- | lib/dijit/form/_FormValueMixin.js.uncompressed.js | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/dijit/form/_FormValueMixin.js.uncompressed.js b/lib/dijit/form/_FormValueMixin.js.uncompressed.js new file mode 100644 index 000000000..4944631ef --- /dev/null +++ b/lib/dijit/form/_FormValueMixin.js.uncompressed.js @@ -0,0 +1,89 @@ +define("dijit/form/_FormValueMixin", [ + "dojo/_base/declare", // declare + "dojo/dom-attr", // domAttr.set + "dojo/keys", // keys.ESCAPE + "dojo/sniff", // has("ie"), has("quirks") + "./_FormWidgetMixin" +], function(declare, domAttr, keys, has, _FormWidgetMixin){ + + // module: + // dijit/form/_FormValueMixin + + return declare("dijit.form._FormValueMixin", _FormWidgetMixin, { + // summary: + // Mixin for widgets corresponding to native HTML elements such as `<input>` or `<select>` + // that have user changeable values. + // description: + // Each _FormValueMixin represents a single input value, and has a (possibly hidden) `<input>` element, + // to which it serializes it's input value, so that form submission (either normal submission or via FormBind?) + // works as expected. + + // readOnly: Boolean + // Should this widget respond to user input? + // In markup, this is specified as "readOnly". + // Similar to disabled except readOnly form values are submitted. + readOnly: false, + + _setReadOnlyAttr: function(/*Boolean*/ value){ + domAttr.set(this.focusNode, 'readOnly', value); + this._set("readOnly", value); + }, + + postCreate: function(){ + this.inherited(arguments); + + if(has("ie")){ // IE won't stop the event with keypress + this.connect(this.focusNode || this.domNode, "onkeydown", this._onKeyDown); + } + // Update our reset value if it hasn't yet been set (because this.set() + // is only called when there *is* a value) + if(this._resetValue === undefined){ + this._lastValueReported = this._resetValue = this.value; + } + }, + + _setValueAttr: function(/*anything*/ newValue, /*Boolean?*/ priorityChange){ + // summary: + // Hook so set('value', value) works. + // description: + // Sets the value of the widget. + // If the value has changed, then fire onChange event, unless priorityChange + // is specified as null (or false?) + this._handleOnChange(newValue, priorityChange); + }, + + _handleOnChange: function(/*anything*/ newValue, /*Boolean?*/ priorityChange){ + // summary: + // Called when the value of the widget has changed. Saves the new value in this.value, + // and calls onChange() if appropriate. See _FormWidget._handleOnChange() for details. + this._set("value", newValue); + this.inherited(arguments); + }, + + undo: function(){ + // summary: + // Restore the value to the last value passed to onChange + this._setValueAttr(this._lastValueReported, false); + }, + + reset: function(){ + // summary: + // Reset the widget's value to what it was at initialization time + this._hasBeenBlurred = false; + this._setValueAttr(this._resetValue, true); + }, + + _onKeyDown: function(e){ + if(e.keyCode == keys.ESCAPE && !(e.ctrlKey || e.altKey || e.metaKey)){ + if(has("ie") < 9 || (has("ie") && has("quirks"))){ + e.preventDefault(); // default behavior needs to be stopped here since keypress is too late + var node = e.srcElement, + te = node.ownerDocument.createEventObject(); + te.keyCode = keys.ESCAPE; + te.shiftKey = e.shiftKey; + node.fireEvent('onkeypress', te); + } + } + } + }); +}); |