Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(!dojo._hasResource["dijit.form.TextBox"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2
dojo._hasResource["dijit.form.TextBox"] = true;
3
dojo.provide("dijit.form.TextBox");
4
 
5
dojo.require("dijit.form._FormWidget");
6
 
7
dojo.declare(
8
	"dijit.form.TextBox",
9
	dijit.form._FormWidget,
10
	{
11
		// summary:
12
		//		A generic textbox field.
13
		//		Serves as a base class to derive more specialized functionality in subclasses.
14
 
15
		//	trim: Boolean
16
		//		Removes leading and trailing whitespace if true.  Default is false.
17
		trim: false,
18
 
19
		//	uppercase: Boolean
20
		//		Converts all characters to uppercase if true.  Default is false.
21
		uppercase: false,
22
 
23
		//	lowercase: Boolean
24
		//		Converts all characters to lowercase if true.  Default is false.
25
		lowercase: false,
26
 
27
		//	propercase: Boolean
28
		//		Converts the first character of each word to uppercase if true.
29
		propercase: false,
30
 
31
		// maxLength: String
32
		//		HTML INPUT tag maxLength declaration.
33
		maxLength: "",
34
 
35
		templateString:"<input class=\"dojoTextBox\" dojoAttachPoint='textbox,focusNode' name=\"${name}\"\n\tdojoAttachEvent='onmouseenter:_onMouse,onmouseleave:_onMouse,onfocus:_onMouse,onblur:_onMouse,onkeyup,onkeypress:_onKeyPress'\n\tautocomplete=\"off\" type=\"${type}\"\n\t/>\n",
36
		baseClass: "dijitTextBox",
37
 
38
		attributeMap: dojo.mixin(dojo.clone(dijit.form._FormWidget.prototype.attributeMap),
39
			{maxLength:"focusNode"}),
40
 
41
		getDisplayedValue: function(){
42
			return this.filter(this.textbox.value);
43
		},
44
 
45
		getValue: function(){
46
			return this.parse(this.getDisplayedValue(), this.constraints);
47
		},
48
 
49
		setValue: function(value, /*Boolean, optional*/ priorityChange, /*String, optional*/ formattedValue){
50
			var filteredValue = this.filter(value);
51
			if((typeof filteredValue == typeof value) && (formattedValue == null || formattedValue == undefined)){
52
				formattedValue = this.format(filteredValue, this.constraints);
53
			}
54
			if(formattedValue != null && formattedValue != undefined){
55
				this.textbox.value = formattedValue;
56
			}
57
			dijit.form.TextBox.superclass.setValue.call(this, filteredValue, priorityChange);
58
		},
59
 
60
		setDisplayedValue: function(/*String*/value){
61
			this.textbox.value = value;
62
			this.setValue(this.getValue(), true);
63
		},
64
 
65
		forWaiValuenow: function(){
66
			return this.getDisplayedValue();
67
		},
68
 
69
		format: function(/* String */ value, /* Object */ constraints){
70
			// summary: Replacable function to convert a value to a properly formatted string
71
			return ((value == null || value == undefined) ? "" : (value.toString ? value.toString() : value));
72
		},
73
 
74
		parse: function(/* String */ value, /* Object */ constraints){
75
			// summary: Replacable function to convert a formatted string to a value
76
			return value;
77
		},
78
 
79
		postCreate: function(){
80
			// setting the value here is needed since value="" in the template causes "undefined"
81
			// and setting in the DOM (instead of the JS object) helps with form reset actions
82
			this.textbox.setAttribute("value", this.getDisplayedValue());
83
			this.inherited('postCreate', arguments);
84
 
85
			if(this.srcNodeRef){
86
				dojo.style(this.textbox, "cssText", this.style);
87
				this.textbox.className += " " + this["class"];
88
			}
89
			this._layoutHack();
90
		},
91
 
92
		_layoutHack: function(){
93
			// summary: work around table sizing bugs on FF2 by forcing redraw
94
			if(dojo.isFF == 2 && this.domNode.tagName=="TABLE"){
95
				var node=this.domNode;
96
				var old = node.style.opacity;
97
				node.style.opacity = "0.999";
98
				setTimeout(function(){
99
					node.style.opacity = old;
100
				}, 0);
101
			}
102
		},
103
 
104
		filter: function(val){
105
			// summary: Apply various filters to textbox value
106
			if(val == undefined || val == null){ return ""; }
107
			else if(typeof val != "string"){ return val; }
108
			if(this.trim){
109
				val = dojo.trim(val);
110
			}
111
			if(this.uppercase){
112
				val = val.toUpperCase();
113
			}
114
			if(this.lowercase){
115
				val = val.toLowerCase();
116
			}
117
			if(this.propercase){
118
				val = val.replace(/[^\s]+/g, function(word){
119
					return word.substring(0,1).toUpperCase() + word.substring(1);
120
				});
121
			}
122
			return val;
123
		},
124
 
125
		// event handlers, you can over-ride these in your own subclasses
126
		_onBlur: function(){
127
			this.setValue(this.getValue(), (this.isValid ? this.isValid() : true));
128
		},
129
 
130
		onkeyup: function(){
131
			// TODO: it would be nice to massage the value (ie: automatic uppercase, etc) as the user types
132
			// but this messes up the cursor position if you are typing into the middle of a word, and
133
			// also trimming doesn't work correctly (it prevents spaces between words too!)
134
			// this.setValue(this.getValue());
135
		}
136
	}
137
);
138
 
139
}