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");
5 dojo.require("dijit.form._FormWidget");
9 dijit.form._FormValueWidget,
12 // A base class for textbox form inputs
15 // Removes leading and trailing whitespace if true. Default is false.
19 // Converts all characters to uppercase if true. Default is false.
23 // Converts all characters to lowercase if true. Default is false.
26 // propercase: Boolean
27 // Converts the first character of each word to uppercase if true.
31 // HTML INPUT tag maxLength declaration.
34 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",
35 baseClass: "dijitTextBox",
37 attributeMap: dojo.mixin(dojo.clone(dijit.form._FormValueWidget.prototype.attributeMap),
38 {maxLength:"focusNode"}),
40 getDisplayedValue: function(){
42 // Returns the formatted value that the user sees in the textbox, which may be different
43 // from the serialized value that's actually sent to the server (see dijit.form.ValidationTextBox.serialize)
44 return this.filter(this.textbox.value);
48 return this.parse(this.getDisplayedValue(), this.constraints);
51 setValue: function(value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
53 // Sets the value of the widget to "value" which can be of
54 // any type as determined by the widget.
57 // The visual element value is also set to a corresponding,
58 // but not necessarily the same, value.
61 // If specified, used to set the visual element value,
62 // otherwise a computed visual value is used.
65 // If true, an onChange event is fired immediately instead of
66 // waiting for the next blur event.
68 var filteredValue = this.filter(value);
69 if((((typeof filteredValue == typeof value) && (value !== undefined/*#5317*/)) || (value === null/*#5329*/)) && (formattedValue == null || formattedValue == undefined)){
70 formattedValue = this.format(filteredValue, this.constraints);
72 if(formattedValue != null && formattedValue != undefined){
73 this.textbox.value = formattedValue;
75 dijit.form.TextBox.superclass.setValue.call(this, filteredValue, priorityChange);
78 setDisplayedValue: function(/*String*/value, /*Boolean?*/ priorityChange){
80 // Sets the value of the visual element to the string "value".
81 // The widget value is also set to a corresponding,
82 // but not necessarily the same, value.
85 // If true, an onChange event is fired immediately instead of
86 // waiting for the next blur event.
88 this.textbox.value = value;
89 this.setValue(this.getValue(), priorityChange);
92 format: function(/* String */ value, /* Object */ constraints){
94 // Replacable function to convert a value to a properly formatted string
95 return ((value == null || value == undefined) ? "" : (value.toString ? value.toString() : value));
98 parse: function(/* String */ value, /* Object */ constraints){
100 // Replacable function to convert a formatted string to a value
104 postCreate: function(){
105 // setting the value here is needed since value="" in the template causes "undefined"
106 // and setting in the DOM (instead of the JS object) helps with form reset actions
107 this.textbox.setAttribute("value", this.getDisplayedValue());
108 this.inherited(arguments);
110 /*#5297:if(this.srcNodeRef){
111 dojo.style(this.textbox, "cssText", this.style);
112 this.textbox.className += " " + this["class"];
117 filter: function(val){
119 // Apply specified filters to textbox value
120 if(val === null || val === undefined){ return ""; }
121 else if(typeof val != "string"){ return val; }
123 val = dojo.trim(val);
126 val = val.toUpperCase();
129 val = val.toLowerCase();
132 val = val.replace(/[^\s]+/g, function(word){
133 return word.substring(0,1).toUpperCase() + word.substring(1);
139 _setBlurValue: function(){
140 this.setValue(this.getValue(), (this.isValid ? this.isValid() : true));
144 this._setBlurValue();
145 this.inherited(arguments);
150 // User replaceable keyup event handler
155 dijit.selectInputText = function(/*DomNode*/element, /*Number?*/ start, /*Number?*/ stop){
157 // Select text in the input element argument, from start (default 0), to stop (default end).
159 // TODO: use functions in _editor/selection.js?
160 var _window = dojo.global;
161 var _document = dojo.doc;
162 element = dojo.byId(element);
163 if(isNaN(start)){ start = 0; }
164 if(isNaN(stop)){ stop = element.value ? element.value.length : 0; }
166 if(_document["selection"] && dojo.body()["createTextRange"]){ // IE
167 if(element.createTextRange){
168 var range = element.createTextRange();
171 moveStart("character", start);
172 moveEnd("character", stop);
176 }else if(_window["getSelection"]){
177 var selection = _window.getSelection();
178 // FIXME: does this work on Safari?
179 if(element.setSelectionRange){
180 element.setSelectionRange(start, stop);