From 8e16e1f6e9b2b79696d03375e2a60fbae6761a64 Mon Sep 17 00:00:00 2001
From: wei <>
Date: Fri, 13 Jan 2006 05:16:37 +0000
Subject: re-focus onchange
---
framework/Web/Javascripts/base/validation.js | 14 +-
framework/Web/Javascripts/js/validator.js | 183 ++++++++++++++-------------
2 files changed, 100 insertions(+), 97 deletions(-)
(limited to 'framework/Web/Javascripts')
diff --git a/framework/Web/Javascripts/base/validation.js b/framework/Web/Javascripts/base/validation.js
index 78694ca4..33d5411d 100644
--- a/framework/Web/Javascripts/base/validation.js
+++ b/framework/Web/Javascripts/base/validation.js
@@ -349,13 +349,9 @@ Prado.Validation.prototype =
validate : function()
{
if(this.visible && this.enabled && this.evaluateIsValid)
- {
this.isValid = this.evaluateIsValid();
- }
else
- {
this.isValid = true;
- }
this.observe(); //watch for changes to the control values
this.update(); //update the validation messages
@@ -379,7 +375,11 @@ Prado.Validation.prototype =
Element.condClassName(this.control, className, !this.isValid);
Prado.Validation.ShowSummary();
- if(this.attr.focusonerror)
+ var focus = this.attr.focusonerror;
+ var hasGroup = Prado.Validation.HasTargetGroup;
+ var inGroup = this.group == Prado.Validation.CurrentTargetGroup;
+
+ if(focus && (!hasGroup || (hasGroup && inGroup)))
Prado.Element.focus(this.attr.focuselementid);
},
@@ -394,14 +394,14 @@ Prado.Validation.prototype =
},
/**
- * Observe changes to the control values, add "onblur" event to the control once.
+ * Observe changes to the control values, add "onchange" event to the control once.
*/
observe : function()
{
if(undef(this.observing))
{
if(this.control && this.control.form)
- Event.observe(this.control, "blur", this.validate.bind(this));
+ Event.observe(this.control, "change", this.validate.bind(this));
this.observing = true;
}
},
diff --git a/framework/Web/Javascripts/js/validator.js b/framework/Web/Javascripts/js/validator.js
index 14808d73..77ff6a1a 100644
--- a/framework/Web/Javascripts/js/validator.js
+++ b/framework/Web/Javascripts/js/validator.js
@@ -185,96 +185,99 @@ if(this.control&&isString(_43)&&_43.length>0){
Element.condClassName(this.control,_43,!this.isValid);
}
Prado.Validation.ShowSummary();
-if(this.attr.focusonerror){
+var _44=this.attr.focusonerror;
+var _45=Prado.Validation.HasTargetGroup;
+var _46=this.group==Prado.Validation.CurrentTargetGroup;
+if(_44&&(!_45||(_45&&_46))){
Prado.Element.focus(this.attr.focuselementid);
}
-},setValid:function(_44){
-this.isValid=_44;
+},setValid:function(_47){
+this.isValid=_47;
this.update();
},observe:function(){
if(undef(this.observing)){
if(this.control&&this.control.form){
-Event.observe(this.control,"blur",this.validate.bind(this));
+Event.observe(this.control,"change",this.validate.bind(this));
}
this.observing=true;
}
-},convert:function(_45,_46){
-if(undef(_46)){
-_46=Form.Element.getValue(this.control);
+},convert:function(_48,_49){
+if(undef(_49)){
+_49=Form.Element.getValue(this.control);
}
-switch(_45){
+switch(_48){
case "Integer":
-return Prado.Validation.Util.toInteger(_46);
+return Prado.Validation.Util.toInteger(_49);
case "Double":
case "Float":
-return Prado.Validation.Util.toDouble(_46,this.attr.decimalchar);
+return Prado.Validation.Util.toDouble(_49,this.attr.decimalchar);
case "Currency":
-return Prado.Validation.Util.toCurrency(_46,this.attr.groupchar,this.attr.digits,this.attr.decimalchar);
+return Prado.Validation.Util.toCurrency(_49,this.attr.groupchar,this.attr.digits,this.attr.decimalchar);
case "Date":
-return Prado.Validation.Util.toDate(_46,this.attr.dateformat);
+return Prado.Validation.Util.toDate(_49,this.attr.dateformat);
}
-return _46.toString();
+return _49.toString();
},inActiveGroup:function(){
-var _47=Prado.Validation.groups;
-for(var i=0;i<_47.length;i++){
-if(_47[i].active&&_47[i].validators.contains(this.attr.id)){
+var _50=Prado.Validation.groups;
+for(var i=0;i<_50.length;i++){
+if(_50[i].active&&_50[i].validators.contains(this.attr.id)){
return true;
}
}
return false;
}};
Prado.Validation.Summary=Class.create();
-Prado.Validation.Summary.prototype={initialize:function(_48){
-this.attr=_48;
-this.div=$(_48.id);
+Prado.Validation.Summary.prototype={initialize:function(_51){
+this.attr=_51;
+this.div=$(_51.id);
this.visible=false;
this.enabled=false;
-this.group=isdef(_48.validationgroup)?_48.validationgroup:null;
+this.group=isdef(_51.validationgroup)?_51.validationgroup:null;
Prado.Validation.summaries.push(this);
-},show:function(_49){
-var _50=_49||this.attr.refresh=="1";
-var _51=this.getMessages();
-if(_51.length<=0||!this.visible||!this.enabled){
-if(_50){
+},show:function(_52){
+var _53=_52||this.attr.refresh=="1";
+var _54=this.getMessages();
+if(_54.length<=0||!this.visible||!this.enabled){
+if(_53){
Element.hide(this.div);
}
return;
}
if(Prado.Validation.HasTargetGroup){
if(Prado.Validation.CurrentTargetGroup!=this.group){
-if(_50){
+if(_53){
Element.hide(this.div);
}
return;
}
}
-if(this.attr.showsummary!="False"&&_50){
+if(this.attr.showsummary!="False"&&_53){
this.div.style.display="block";
while(this.div.childNodes.length>0){
this.div.removeChild(this.div.lastChild);
}
-new Insertion.Bottom(this.div,this.formatSummary(_51));
+new Insertion.Bottom(this.div,this.formatSummary(_54));
}
-if(_49){
+if(_52){
window.scrollTo(this.div.offsetLeft-20,this.div.offsetTop-20);
}
-var _52=this;
-if(_49&&this.attr.showmessagebox=="True"&&_50){
+var _55=this;
+if(_52&&this.attr.showmessagebox=="True"&&_53){
setTimeout(function(){
-alert(_52.formatMessageBox(_51));
+alert(_55.formatMessageBox(_54));
},20);
}
},getMessages:function(){
-var _53=Prado.Validation.validators;
-var _54=[];
-for(var i=0;i<_53.length;i++){
-if(_53[i].isValid==false&&isString(_53[i].attr.errormessage)&&_53[i].attr.errormessage.length>0){
-_54.push(_53[i].attr.errormessage);
+var _56=Prado.Validation.validators;
+var _57=[];
+for(var i=0;i<_56.length;i++){
+if(_56[i].isValid==false&&isString(_56[i].attr.errormessage)&&_56[i].attr.errormessage.length>0){
+_57.push(_56[i].attr.errormessage);
}
}
-return _54;
-},formats:function(_55){
-switch(_55){
+return _57;
+},formats:function(_58){
+switch(_58){
case "List":
return {header:"
",first:"",pre:"",post:"
",last:""};
case "SingleParagraph":
@@ -283,53 +286,53 @@ case "BulletList":
default:
return {header:"",first:"