Debian Codegraph @

dijit/form/_FormValueMixin.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare", // declare
3 "dojo/dom-attr", // domAttr.set
4 "dojo/keys", // keys.ESCAPE
5 "dojo/_base/lang",
6 "dojo/on",
7 "dojo/sniff", // has("webkit")
8 "./_FormWidgetMixin"
9 ], function(declare, domAttr, keys, lang, on, has, _FormWidgetMixin){
10
11 // module:
12 // dijit/form/_FormValueMixin
13
14 return declare("dijit.form._FormValueMixin", _FormWidgetMixin, {
15 // summary:
16 // Mixin for widgets corresponding to native HTML elements such as `<input>` or `<select>`
17 // that have user changeable values.
18 // description:
19 // Each _FormValueMixin represents a single input value, and has a (possibly hidden) `<input>` element,
20 // to which it serializes it's input value, so that form submission (either normal submission or via FormBind?)
21 // works as expected.
22
23 // readOnly: Boolean
24 // Should this widget respond to user input?
25 // In markup, this is specified as "readOnly".
26 // Similar to disabled except readOnly form values are submitted.
27 readOnly: false,
28
29 _setReadOnlyAttr: function(/*Boolean*/ value){
30 // IE has a Caret Browsing mode (hit F7 to activate) where disabled textboxes can be modified
31 // focusNode enforced readonly if currently disabled to avoid this issue.
32 if (has('trident') && 'disabled' in this) {
33 domAttr.set(this.focusNode, 'readOnly', value || this.disabled);
34 } else {
35 domAttr.set(this.focusNode, 'readOnly', value);
36 }
37 this._set("readOnly", value);
38 },
39
40 postCreate: function(){
41 this.inherited(arguments);
42
43 // Update our reset value if it hasn't yet been set (because this.set()
44 // is only called when there *is* a value)
45 if(this._resetValue === undefined){
46 this._lastValueReported = this._resetValue = this.value;
47 }
48 },
49
50 _setValueAttr: function(/*anything*/ newValue, /*Boolean?*/ priorityChange){
51 // summary:
52 // Hook so set('value', value) works.
53 // description:
54 // Sets the value of the widget.
55 // If the value has changed, then fire onChange event, unless priorityChange
56 // is specified as null (or false?)
57 this._handleOnChange(newValue, priorityChange);
58 },
59
60 _handleOnChange: function(/*anything*/ newValue, /*Boolean?*/ priorityChange){
61 // summary:
62 // Called when the value of the widget has changed. Saves the new value in this.value,
63 // and calls onChange() if appropriate. See _FormWidget._handleOnChange() for details.
64 this._set("value", newValue);
65 this.inherited(arguments);
66 },
67
68 undo: function(){
69 // summary:
70 // Restore the value to the last value passed to onChange
71 this._setValueAttr(this._lastValueReported, false);
72 },
73
74 reset: function(){
75 // summary:
76 // Reset the widget's value to what it was at initialization time
77 this._hasBeenBlurred = false;
78 this._setValueAttr(this._resetValue, true);
79 }
80 });
81 });