From 8da0f8dd4a0347f15df6e71ac2b0f4b3c27e8475 Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 13 Jan 2006 04:55:22 +0000 Subject: Focus added to client validators --- framework/Web/Javascripts/js/dom.js | 273 +++++++++++++++++++++++++----- framework/Web/Javascripts/js/validator.js | 65 +++++-- 2 files changed, 290 insertions(+), 48 deletions(-) (limited to 'framework/Web/Javascripts/js') diff --git a/framework/Web/Javascripts/js/dom.js b/framework/Web/Javascripts/js/dom.js index b93a6c63..4a4904ad 100644 --- a/framework/Web/Javascripts/js/dom.js +++ b/framework/Web/Javascripts/js/dom.js @@ -292,23 +292,31 @@ for(var i=0;i<_18.length;i++){ el.options[el.options.length]=new Option(_18[i][0],_18[i][1]); } } +},focus:function(_20){ +var obj=$(_20); +if(isObject(obj)&&isdef(obj.focus)){ +setTimeout(function(){ +obj.focus(); +},100); +} +return false; }}; -Prado.Element.Selection={inputValue:function(el,_20){ +Prado.Element.Selection={inputValue:function(el,_22){ switch(el.type.toLowerCase()){ case "checkbox": case "radio": -return el.checked=_20; +return el.checked=_22; } -},selectValue:function(el,_21){ -$A(el.options).each(function(_22){ -_22.selected=_22.value==_21; +},selectValue:function(el,_23){ +$A(el.options).each(function(_24){ +_24.selected=_24.value==_23; }); -},selectIndex:function(el,_23){ +},selectIndex:function(el,_25){ if(el.type=="select-one"){ -el.selectedIndex=_23; +el.selectedIndex=_25; }else{ for(var i=0;i=_18;x--){ +var _21=str.substring(i,i+x); +if(_21.length<_18){ +return null; +} +if(_12(_21)){ +return _21; +} +} +return null; +}; +var _22=0; +var _23=0; +var c=""; +var _25=""; +var _26=""; +var x,y; +var now=new Date(); +var _28=now.getFullYear(); +var _29=now.getMonth()+1; +var _30=1; +while(_23<_11.length){ +c=_11.charAt(_23); +_25=""; +while((_11.charAt(_23)==c)&&(_23<_11.length)){ +_25+=_11.charAt(_23++); +} +if(_25=="yyyy"||_25=="yy"||_25=="y"){ +if(_25=="yyyy"){ +x=4; +y=4; +} +if(_25=="yy"){ +x=2; +y=2; +} +if(_25=="y"){ +x=2; +y=4; +} +_28=_16(val,_22,x,y); +if(_28==null){ +return null; +} +_22+=_28.length; +if(_28.length==2){ +if(_28>70){ +_28=1900+(_28-0); +}else{ +_28=2000+(_28-0); +} +} +}else{ +if(_25=="MM"||_25=="M"){ +_29=_16(val,_22,_25.length,2); +if(_29==null||(_29<1)||(_29>12)){ +return null; +} +_22+=_29.length; +}else{ +if(_25=="dd"||_25=="d"){ +_30=_16(val,_22,_25.length,2); +if(_30==null||(_30<1)||(_30>31)){ +return null; +} +_22+=_30.length; +}else{ +if(val.substring(_22,_22+_25.length)!=_25){ +return null; +}else{ +_22+=_25.length; +} +} +} +} +} +if(_22!=val.length){ +return null; +} +if(_29==2){ +if(((_28%4==0)&&(_28%100!=0))||(_28%400==0)){ +if(_30>29){ +return null; +} +}else{ +if(_30>28){ +return null; +} +} +} +if((_29==4)||(_29==6)||(_29==9)||(_29==11)){ +if(_30>30){ +return null; +} +} +var _31=new Date(_28,_29-1,_30,0,0,0); +return _31; +}}); + +Prado.Util={}; +Prado.Util.pad=function(_1,X){ +X=(!X?2:X); +_1=""+_1; +while(_1.length0?m[2]:"0")+"."+m[4]; +var num=parseFloat(_10); +return (isNaN(num)?null:num); +}; +Prado.Util.toCurrency=function(_12,_13,_14,_15){ +_13=undef(_13)?",":_13; +_15=undef(_15)?".":_15; +_14=undef(_14)?2:_14; +var exp=new RegExp("^\\s*([-\\+])?(((\\d+)\\"+_13+")*)(\\d+)"+((_14>0)?"(\\"+_15+"(\\d{1,"+_14+"}))?":"")+"\\s*$"); +var m=_12.match(exp); +if(m==null){ +return null; +} +var _17=m[2]+m[5]; +var _18=m[1]+_17.replace(new RegExp("(\\"+_13+")","g"),"")+((_14>0)?"."+m[7]:""); +var num=parseFloat(_18); +return (isNaN(num)?null:num); +}; +Prado.Util.trim=function(_19){ +if(!isString(_19)){ +return ""; +} +return _19.replace(/^\s+|\s+$/g,""); +}; + diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js index 6f347756..14808d73 100644 --- a/framework/Web/Javascripts/js/validator.js +++ b/framework/Web/Javascripts/js/validator.js @@ -83,7 +83,7 @@ return (isObject(_27)&&y==_27.getFullYear()&&m==_27.getMonth()&&d==_27.getDate() return null; }; Prado.Validation.Util.trim=function(_28){ -if(!isString(_28)){ +if(undef(_28)){ return ""; } return _28.replace(/^\s+|\s+$/g,""); @@ -185,6 +185,9 @@ if(this.control&&isString(_43)&&_43.length>0){ Element.condClassName(this.control,_43,!this.isValid); } Prado.Validation.ShowSummary(); +if(this.attr.focusonerror){ +Prado.Element.focus(this.attr.focuselementid); +} },setValid:function(_44){ this.isValid=_44; this.update(); @@ -346,6 +349,48 @@ return _64; Prado.Validation.OnLoad=function(){ Event.observe(Prado.Validation.forms,"submit",Prado.Validation.OnSubmit); }; +Prado.Validation.ValidateValidatorGroup=function(_65){ +var _66=Prado.Validation.groups; +var _67=null; +for(var i=0;i<_66.length;i++){ +if(_66[i].id==_65){ +_67=_66[i]; +Prado.Validation.groups[i].active=true; +Prado.Validation.CurrentTargetGroup=null; +Prado.Validation.IsGroupValidation=true; +}else{ +Prado.Validation.groups[i].active=false; +} +} +if(_67){ +return Prado.Validation.IsValid(_67.target.form); +} +return true; +}; +Prado.Validation.ValidateValidationGroup=function(_68){ +var _69=Prado.Validation.TargetGroups; +for(var id in _69){ +if(_69[id]==_68){ +var _70=$(id); +Prado.Validation.ActiveTarget=_70; +Prado.Validation.CurrentTargetGroup=_68; +Prado.Validation.IsGroupValidation=false; +return Prado.Validation.IsValid(_70.form); +} +} +return true; +}; +Prado.Validation.ValidateNonGroup=function(_71){ +if(Prado.Validation){ +var _72=$(_71); +_72=_72||document.forms[0]; +Prado.Validation.ActiveTarget=_72; +Prado.Validation.CurrentTargetGroup=null; +Prado.Validation.IsGroupValidation=false; +return Prado.Validation.IsValid(_72); +} +return true; +}; Event.OnLoad(Prado.Validation.OnLoad); Prado.Validation.TRequiredFieldValidator=function(){ @@ -353,15 +398,15 @@ var _1=this.control.getAttribute("type"); if(_1=="file"){ return true; }else{ -var _2=Prado.Validation.Util.trim; -var a=_2($F(this.control)); +var _2=Prado.Util.trim; +var a=_2(Form.Element.getValue(this.control)); var b=_2(this.attr.initialvalue); return (a!=b); } }; Prado.Validation.TRegularExpressionValidator=function(){ -var _5=Prado.Validation.Util.trim; -var _6=_5($F(this.control)); +var _5=Prado.Util.trim; +var _6=_5(Form.Element.getValue(this.control)); if(_6==""){ return true; } @@ -377,8 +422,8 @@ eval("var validate = "+_10); return validate&&isFunction(validate)?validate(this,_9):true; }; Prado.Validation.TRangeValidator=function(){ -var _11=Prado.Validation.Util.trim; -var _12=_11($F(this.control)); +var _11=Prado.Util.trim; +var _12=_11(Form.Element.getValue(this.control)); if(_12==""){ return true; } @@ -403,15 +448,15 @@ _12=this.convert(_15,_12); return _12>=min&&_12<=max; }; Prado.Validation.TCompareValidator=function(){ -var _18=Prado.Validation.Util.trim; -var _19=_18($F(this.control)); +var _18=Prado.Util.trim; +var _19=_18(Form.Element.getValue(this.control)); if(_19.length==0){ return true; } var _20; var _21=$(this.attr.controlhookup); if(_21){ -_20=_18($F(_21)); +_20=_18(Form.Element.getValue(_21)); }else{ _20=isString(this.attr.valuetocompare)?this.attr.valuetocompare:""; } -- cgit v1.2.3