root / trunk / web / dojo / dijit / form / NumberTextBox.js @ 10
History | View | Annotate | Download (2.98 KB)
1 |
/*
|
---|---|
2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
4 |
see: http://dojotoolkit.org/license for details
|
5 |
*/
|
6 |
|
7 |
|
8 |
if(!dojo._hasResource["dijit.form.NumberTextBox"]){ |
9 |
dojo._hasResource["dijit.form.NumberTextBox"]=true; |
10 |
dojo.provide("dijit.form.NumberTextBox");
|
11 |
dojo.require("dijit.form.ValidationTextBox");
|
12 |
dojo.require("dojo.number");
|
13 |
dojo.declare("dijit.form.NumberTextBoxMixin",null,{regExpGen:dojo.number.regexp,value:NaN,editOptions:{pattern:"#.######"},_formatter:dojo.number.format,_setConstraintsAttr:function(_1){ |
14 |
var _2=typeof _1.places=="number"?_1.places:0; |
15 |
if(_2){
|
16 |
_2++; |
17 |
} |
18 |
if(typeof _1.max!="number"){ |
19 |
_1.max=9*Math.pow(10,15-_2); |
20 |
} |
21 |
if(typeof _1.min!="number"){ |
22 |
_1.min=-9*Math.pow(10,15-_2); |
23 |
} |
24 |
this.inherited(arguments,[_1]); |
25 |
if(this.focusNode&&this.focusNode.value&&!isNaN(this.value)){ |
26 |
this.set("value",this.value); |
27 |
} |
28 |
},_onFocus:function(){ |
29 |
if(this.disabled){ |
30 |
return;
|
31 |
} |
32 |
var _3=this.get("value"); |
33 |
if(typeof _3=="number"&&!isNaN(_3)){ |
34 |
var _4=this.format(_3,this.constraints); |
35 |
if(_4!==undefined){ |
36 |
this.textbox.value=_4;
|
37 |
} |
38 |
} |
39 |
this.inherited(arguments); |
40 |
},format:function(_5,_6){ |
41 |
var _7=String(_5);
|
42 |
if(typeof _5!="number"){ |
43 |
return _7;
|
44 |
} |
45 |
if(isNaN(_5)){
|
46 |
return ""; |
47 |
} |
48 |
if(!("rangeCheck" in this&&this.rangeCheck(_5,_6))&&_6.exponent!==false&&/\de[-+]?\d/i.test(_7)){ |
49 |
return _7;
|
50 |
} |
51 |
if(this.editOptions&&this._focused){ |
52 |
_6=dojo.mixin({},_6,this.editOptions);
|
53 |
} |
54 |
return this._formatter(_5,_6); |
55 |
},parse:dojo.number.parse,_getDisplayedValueAttr:function(){ |
56 |
var v=this.inherited(arguments); |
57 |
return isNaN(v)?this.textbox.value:v; |
58 |
},filter:function(_8){ |
59 |
return (_8===null||_8===""||_8===undefined)?NaN:this.inherited(arguments); |
60 |
},serialize:function(_9,_a){ |
61 |
return (typeof _9!="number"||isNaN(_9))?"":this.inherited(arguments); |
62 |
},_setValueAttr:function(_b,_c,_d){ |
63 |
if(_b!==undefined&&_d===undefined){ |
64 |
_d=String(_b); |
65 |
if(typeof _b=="number"){ |
66 |
if(isNaN(_b)){
|
67 |
_d="";
|
68 |
}else{
|
69 |
if(("rangeCheck" in this&&this.rangeCheck(_b,this.constraints))||this.constraints.exponent===false||!/\de[-+]?\d/i.test(_d)){ |
70 |
_d=undefined;
|
71 |
} |
72 |
} |
73 |
}else{
|
74 |
if(!_b){
|
75 |
_d="";
|
76 |
_b=NaN;
|
77 |
}else{
|
78 |
_b=undefined;
|
79 |
} |
80 |
} |
81 |
} |
82 |
this.inherited(arguments,[_b,_c,_d]); |
83 |
},_getValueAttr:function(){ |
84 |
var v=this.inherited(arguments); |
85 |
if(isNaN(v)&&this.textbox.value!==""){ |
86 |
if(this.constraints.exponent!==false&&/\de[-+]?\d/i.test(this.textbox.value)&&(new RegExp("^"+dojo.number._realNumberRegexp(dojo.mixin({},this.constraints))+"$").test(this.textbox.value))){ |
87 |
var n=Number(this.textbox.value); |
88 |
return isNaN(n)?undefined:n; |
89 |
}else{
|
90 |
return undefined; |
91 |
} |
92 |
}else{
|
93 |
return v;
|
94 |
} |
95 |
},isValid:function(_e){ |
96 |
if(!this._focused||this._isEmpty(this.textbox.value)){ |
97 |
return this.inherited(arguments); |
98 |
}else{
|
99 |
var v=this.get("value"); |
100 |
if(!isNaN(v)&&this.rangeCheck(v,this.constraints)){ |
101 |
if(this.constraints.exponent!==false&&/\de[-+]?\d/i.test(this.textbox.value)){ |
102 |
return true; |
103 |
}else{
|
104 |
return this.inherited(arguments); |
105 |
} |
106 |
}else{
|
107 |
return false; |
108 |
} |
109 |
} |
110 |
}}); |
111 |
dojo.declare("dijit.form.NumberTextBox",[dijit.form.RangeBoundTextBox,dijit.form.NumberTextBoxMixin],{});
|
112 |
} |