]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/ValidationTextBox.js
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
8 if(!dojo
._hasResource
["dijit.form.ValidationTextBox"]){
9 dojo
._hasResource
["dijit.form.ValidationTextBox"]=true;
10 dojo
.provide("dijit.form.ValidationTextBox");
11 dojo
.require("dojo.i18n");
12 dojo
.require("dijit.form.TextBox");
13 dojo
.require("dijit.Tooltip");
14 dojo
.requireLocalization("dijit.form","validate",null,"ROOT,ar,ca,cs,da,de,el,es,fi,fr,he,hu,it,ja,ko,nb,nl,pl,pt,pt-pt,ro,ru,sk,sl,sv,th,tr,zh,zh-tw");
15 dojo
.declare("dijit.form.ValidationTextBox",dijit
.form
.TextBox
,{templateString
:dojo
.cache("dijit.form","templates/ValidationTextBox.html","<div class=\"dijit dijitReset dijitInlineTable dijitLeft\"\n\tid=\"widget_${id}\" waiRole=\"presentation\"\n\t><div class='dijitReset dijitValidationContainer'\n\t\t><input class=\"dijitReset dijitInputField dijitValidationIcon dijitValidationInner\" value=\"Χ \" type=\"text\" tabIndex=\"-1\" readOnly waiRole=\"presentation\"\n\t/></div\n\t><div class=\"dijitReset dijitInputField dijitInputContainer\"\n\t\t><input class=\"dijitReset dijitInputInner\" dojoAttachPoint='textbox,focusNode' autocomplete=\"off\"\n\t\t\t${!nameAttrSetting} type='${type}'\n\t/></div\n></div>\n"),baseClass
:"dijitTextBox dijitValidationTextBox",required
:false,promptMessage
:"",invalidMessage
:"$_unset_$",missingMessage
:"$_unset_$",constraints
:{},regExp
:".*",regExpGen:function(_1
){
17 },state
:"",tooltipPosition
:[],_setValueAttr:function(){
18 this.inherited(arguments
);
19 this.validate(this._focused
);
20 },validator:function(_2
,_3
){
21 return (new RegExp("^(?:"+this.regExpGen(_3
)+")"+(this.required
?"":"?")+"$")).test(_2
)&&(!this.required
||!this._isEmpty(_2
))&&(this._isEmpty(_2
)||this.parse(_2
,_3
)!==undefined);
22 },_isValidSubset:function(){
23 return this.textbox
.value
.search(this._partialre
)==0;
24 },isValid:function(_4
){
25 return this.validator(this.textbox
.value
,this.constraints
);
26 },_isEmpty:function(_5
){
27 return /^\s*$/.test(_5
);
28 },getErrorMessage:function(_6
){
29 return (this.required
&&this._isEmpty(this.textbox
.value
))?this.missingMessage
:this.invalidMessage
;
30 },getPromptMessage:function(_7
){
31 return this.promptMessage
;
32 },_maskValidSubsetError
:true,validate:function(_8
){
34 var _a
=this.disabled
||this.isValid(_8
);
36 this._maskValidSubsetError
=true;
38 var _b
=this._isEmpty(this.textbox
.value
);
39 var _c
=!_a
&&!_b
&&_8
&&this._isValidSubset();
40 this.state
=((_a
||((!this._hasBeenBlurred
||_8
)&&_b
)||_c
)&&this._maskValidSubsetError
)?"":"Error";
41 if(this.state
=="Error"){
42 this._maskValidSubsetError
=_8
;
44 this._setStateClass();
45 dijit
.setWaiState(this.focusNode
,"invalid",_a
?"false":"true");
47 if(this.state
=="Error"){
48 _9
=this.getErrorMessage(true);
50 _9
=this.getPromptMessage(true);
52 this._maskValidSubsetError
=true;
54 this.displayMessage(_9
);
56 },_message
:"",displayMessage:function(_d
){
57 if(this._message
==_d
){
61 dijit
.hideTooltip(this.domNode
);
63 dijit
.showTooltip(_d
,this.domNode
,this.tooltipPosition
,!this.isLeftToRight());
65 },_refreshState:function(){
66 this.validate(this._focused
);
67 this.inherited(arguments
);
68 },constructor:function(){
70 },_setConstraintsAttr:function(_e
){
71 if(!_e
.locale
&&this.lang
){
75 this._computePartialRE();
76 },_computePartialRE:function(){
77 var p
=this.regExpGen(this.constraints
);
81 this.regExp
.replace(/\\.|\[\]|\[.*?[^\\]{1}\]|\{.*?\}|\(\?[=:!]|./g,function(re
){
107 console
.warn("RegExp error in "+this.declaredClass
+": "+this.regExp
);
109 this._partialre
="^(?:"+_f
+")$";
110 },postMixInProperties:function(){
111 this.inherited(arguments
);
112 this.messages
=dojo
.i18n
.getLocalization("dijit.form","validate",this.lang
);
113 if(this.invalidMessage
=="$_unset_$"){
114 this.invalidMessage
=this.messages
.invalidMessage
;
116 if(!this.invalidMessage
){
117 this.invalidMessage
=this.promptMessage
;
119 if(this.missingMessage
=="$_unset_$"){
120 this.missingMessage
=this.messages
.missingMessage
;
122 if(!this.missingMessage
){
123 this.missingMessage
=this.invalidMessage
;
125 this._setConstraintsAttr(this.constraints
);
126 },_setDisabledAttr:function(_10
){
127 this.inherited(arguments
);
128 this._refreshState();
129 },_setRequiredAttr:function(_11
){
131 dijit
.setWaiState(this.focusNode
,"required",_11
);
132 this._refreshState();
134 this._maskValidSubsetError
=true;
135 this.inherited(arguments
);
136 },_onBlur:function(){
137 this.displayMessage("");
138 this.inherited(arguments
);
140 dojo
.declare("dijit.form.MappedTextBox",dijit
.form
.ValidationTextBox
,{postMixInProperties:function(){
141 this.inherited(arguments
);
142 this.nameAttrSetting
="";
143 },serialize:function(val
,_12
){
144 return val
.toString
?val
.toString():"";
145 },toString:function(){
146 var val
=this.filter(this.get("value"));
147 return val
!=null?(typeof val
=="string"?val
:this.serialize(val
,this.constraints
)):"";
148 },validate:function(){
149 this.valueNode
.value
=this.toString();
150 return this.inherited(arguments
);
151 },buildRendering:function(){
152 this.inherited(arguments
);
153 this.valueNode
=dojo
.place("<input type='hidden'"+(this.name
?" name='"+this.name
+"'":"")+">",this.textbox
,"after");
155 this.valueNode
.value
="";
156 this.inherited(arguments
);
158 dojo
.declare("dijit.form.RangeBoundTextBox",dijit
.form
.MappedTextBox
,{rangeMessage
:"",rangeCheck:function(_13
,_14
){
159 return ("min" in _14
?(this.compare(_13
,_14
.min
)>=0):true)&&("max" in _14
?(this.compare(_13
,_14
.max
)<=0):true);
160 },isInRange:function(_15
){
161 return this.rangeCheck(this.get("value"),this.constraints
);
162 },_isDefinitelyOutOfRange:function(){
163 var val
=this.get("value");
166 if("min" in this.constraints
){
167 var min
=this.constraints
.min
;
168 min
=this.compare(val
,((typeof min
=="number")&&min
>=0&&val
!=0)?0:min
);
169 _16
=(typeof min
=="number")&&min
<0;
171 if("max" in this.constraints
){
172 var max
=this.constraints
.max
;
173 max
=this.compare(val
,((typeof max
!="number")||max
>0)?max
:0);
174 _17
=(typeof max
=="number")&&max
>0;
177 },_isValidSubset:function(){
178 return this.inherited(arguments
)&&!this._isDefinitelyOutOfRange();
179 },isValid:function(_18
){
180 return this.inherited(arguments
)&&((this._isEmpty(this.textbox
.value
)&&!this.required
)||this.isInRange(_18
));
181 },getErrorMessage:function(_19
){
182 var v
=this.get("value");
183 if(v
!==null&&v
!==""&&v
!==undefined&&(typeof v
!="number"||!isNaN(v
))&&!this.isInRange(_19
)){
184 return this.rangeMessage
;
186 return this.inherited(arguments
);
187 },postMixInProperties:function(){
188 this.inherited(arguments
);
189 if(!this.rangeMessage
){
190 this.messages
=dojo
.i18n
.getLocalization("dijit.form","validate",this.lang
);
191 this.rangeMessage
=this.messages
.rangeMessage
;
193 },_setConstraintsAttr:function(_1a
){
194 this.inherited(arguments
);
196 if(this.constraints
.min
!==undefined){
197 dijit
.setWaiState(this.focusNode
,"valuemin",this.constraints
.min
);
199 dijit
.removeWaiState(this.focusNode
,"valuemin");
201 if(this.constraints
.max
!==undefined){
202 dijit
.setWaiState(this.focusNode
,"valuemax",this.constraints
.max
);
204 dijit
.removeWaiState(this.focusNode
,"valuemax");
207 },_setValueAttr:function(_1b
,_1c
){
208 dijit
.setWaiState(this.focusNode
,"valuenow",_1b
);
209 this.inherited(arguments
);