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