1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
if(!dojo._hasResource["dijit.form.TextBox"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
dojo._hasResource["dijit.form.TextBox"] = true;
dojo.provide("dijit.form.TextBox");
dojo.require("dijit.form._FormWidget");
dojo.declare(
"dijit.form.TextBox",
dijit.form._FormValueWidget,
{
// summary:
// A base class for textbox form inputs
//
// trim: Boolean
// Removes leading and trailing whitespace if true. Default is false.
trim: false,
// uppercase: Boolean
// Converts all characters to uppercase if true. Default is false.
uppercase: false,
// lowercase: Boolean
// Converts all characters to lowercase if true. Default is false.
lowercase: false,
// propercase: Boolean
// Converts the first character of each word to uppercase if true.
propercase: false,
// maxLength: String
// HTML INPUT tag maxLength declaration.
maxLength: "",
templateString:"<input class=\"dijit dijitReset dijitLeft\" dojoAttachPoint='textbox,focusNode' name=\"${name}\"\n\tdojoAttachEvent='onmouseenter:_onMouse,onmouseleave:_onMouse,onfocus:_onMouse,onblur:_onMouse,onkeypress:_onKeyPress,onkeyup'\n\tautocomplete=\"off\" type=\"${type}\"\n\t/>\n",
baseClass: "dijitTextBox",
attributeMap: dojo.mixin(dojo.clone(dijit.form._FormValueWidget.prototype.attributeMap),
{maxLength:"focusNode"}),
getDisplayedValue: function(){
// summary:
// Returns the formatted value that the user sees in the textbox, which may be different
// from the serialized value that's actually sent to the server (see dijit.form.ValidationTextBox.serialize)
return this.filter(this.textbox.value);
},
getValue: function(){
return this.parse(this.getDisplayedValue(), this.constraints);
},
setValue: function(value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
// summary:
// Sets the value of the widget to "value" which can be of
// any type as determined by the widget.
//
// value:
// The visual element value is also set to a corresponding,
// but not necessarily the same, value.
//
// formattedValue:
// If specified, used to set the visual element value,
// otherwise a computed visual value is used.
//
// priorityChange:
// If true, an onChange event is fired immediately instead of
// waiting for the next blur event.
var filteredValue = this.filter(value);
if((((typeof filteredValue == typeof value) && (value !== undefined/*#5317*/)) || (value === null/*#5329*/)) && (formattedValue == null || formattedValue == undefined)){
formattedValue = this.format(filteredValue, this.constraints);
}
if(formattedValue != null && formattedValue != undefined){
this.textbox.value = formattedValue;
}
dijit.form.TextBox.superclass.setValue.call(this, filteredValue, priorityChange);
},
setDisplayedValue: function(/*String*/value, /*Boolean?*/ priorityChange){
// summary:
// Sets the value of the visual element to the string "value".
// The widget value is also set to a corresponding,
// but not necessarily the same, value.
//
// priorityChange:
// If true, an onChange event is fired immediately instead of
// waiting for the next blur event.
this.textbox.value = value;
this.setValue(this.getValue(), priorityChange);
},
format: function(/* String */ value, /* Object */ constraints){
// summary:
// Replacable function to convert a value to a properly formatted string
return ((value == null || value == undefined) ? "" : (value.toString ? value.toString() : value));
},
parse: function(/* String */ value, /* Object */ constraints){
// summary:
// Replacable function to convert a formatted string to a value
return value;
},
postCreate: function(){
// setting the value here is needed since value="" in the template causes "undefined"
// and setting in the DOM (instead of the JS object) helps with form reset actions
this.textbox.setAttribute("value", this.getDisplayedValue());
this.inherited(arguments);
/*#5297:if(this.srcNodeRef){
dojo.style(this.textbox, "cssText", this.style);
this.textbox.className += " " + this["class"];
}*/
this._layoutHack();
},
filter: function(val){
// summary:
// Apply specified filters to textbox value
if(val === null || val === undefined){ return ""; }
else if(typeof val != "string"){ return val; }
if(this.trim){
val = dojo.trim(val);
}
if(this.uppercase){
val = val.toUpperCase();
}
if(this.lowercase){
val = val.toLowerCase();
}
if(this.propercase){
val = val.replace(/[^\s]+/g, function(word){
return word.substring(0,1).toUpperCase() + word.substring(1);
});
}
return val;
},
_setBlurValue: function(){
this.setValue(this.getValue(), (this.isValid ? this.isValid() : true));
},
_onBlur: function(){
this._setBlurValue();
this.inherited(arguments);
},
onkeyup: function(){
// summary:
// User replaceable keyup event handler
}
}
);
dijit.selectInputText = function(/*DomNode*/element, /*Number?*/ start, /*Number?*/ stop){
// summary:
// Select text in the input element argument, from start (default 0), to stop (default end).
// TODO: use functions in _editor/selection.js?
var _window = dojo.global;
var _document = dojo.doc;
element = dojo.byId(element);
if(isNaN(start)){ start = 0; }
if(isNaN(stop)){ stop = element.value ? element.value.length : 0; }
element.focus();
if(_document["selection"] && dojo.body()["createTextRange"]){ // IE
if(element.createTextRange){
var range = element.createTextRange();
with(range){
collapse(true);
moveStart("character", start);
moveEnd("character", stop);
select();
}
}
}else if(_window["getSelection"]){
var selection = _window.getSelection();
// FIXME: does this work on Safari?
if(element.setSelectionRange){
element.setSelectionRange(start, stop);
}
}
}
}
|