Author: igorz
Date: 2007-02-12 05:17:20 -0500 (Mon, 12 Feb 2007)
New Revision: 72638
Modified:
trunk/mcs/class/System.Web/System.Web.UI.WebControls/BaseValidator.cs
trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
trunk/mcs/class/System.Web/resources/WebUIValidation_2.0.js
Log:
2007-02-12 Igor Zelmanovich <[EMAIL PROTECTED]>
* BaseValidator.cs: implemented SetFocusOnError feature.
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/BaseValidator.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/BaseValidator.cs
2007-02-12 09:13:38 UTC (rev 72637)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/BaseValidator.cs
2007-02-12 10:17:20 UTC (rev 72638)
@@ -223,6 +223,9 @@
#if NET_2_0
if (ValidationGroup != String.Empty)
writer.AddAttribute ("validationgroup",
ValidationGroup);
+
+ if (SetFocusOnError)
+
Page.ClientScript.RegisterExpandoAttribute (ClientID, "focusOnError", "t");
#endif
if (!Enabled)
writer.AddAttribute ("enabled",
"false");
Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2007-02-12 09:13:38 UTC (rev 72637)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
2007-02-12 10:17:20 UTC (rev 72638)
@@ -1,3 +1,7 @@
+2007-02-12 Igor Zelmanovich <[EMAIL PROTECTED]>
+
+ * BaseValidator.cs: implemented SetFocusOnError feature.
+
2007-02-11 Igor Zelmanovich <[EMAIL PROTECTED]>
* Wizard.cs: refactoring:
Modified: trunk/mcs/class/System.Web/resources/WebUIValidation_2.0.js
===================================================================
--- trunk/mcs/class/System.Web/resources/WebUIValidation_2.0.js 2007-02-12
09:13:38 UTC (rev 72637)
+++ trunk/mcs/class/System.Web/resources/WebUIValidation_2.0.js 2007-02-12
10:17:20 UTC (rev 72638)
@@ -193,7 +193,8 @@
vs.innerHTML = "";
}
}
-
+
+ var invalidControlHasBeenFocused = false;
for (var v = 0; v < Page_Validators.length; v++) {
var vo = Page_Validators [v];
var evalfunc = this[vo.getAttribute ("evaluationfunction")];
@@ -207,9 +208,13 @@
result = evalfunc (vo);
}
- if (!result)
+ if (!result) {
validation_result = false;
-
+ if (!invalidControlHasBeenFocused &&
typeof(vo.focusOnError) == "string" && vo.focusOnError == "t") {
+ invalidControlHasBeenFocused =
ValidatorSetFocus(vo);
+ }
+ }
+
vo.setAttribute("isvalid", result ? "true" : "false");
}
ValidationSummaryOnSubmit(group);
@@ -224,6 +229,40 @@
return (valGroup == group);
}
+function ValidatorSetFocus(val) {
+ var ctrl = document.getElementById(val.getAttribute ("controltovalidate"));
+ if ((typeof(ctrl) != "undefined") && (ctrl != null) &&
+ ((ctrl.tagName.toLowerCase() != "input") ||
(ctrl.type.toLowerCase() != "hidden")) &&
+ (typeof(ctrl.disabled) == "undefined" || ctrl.disabled == null
|| ctrl.disabled == false) &&
+ (typeof(ctrl.visible) == "undefined" || ctrl.visible == null ||
ctrl.visible != false) &&
+ (IsInVisibleContainer(ctrl))) {
+ if (ctrl.tagName.toLowerCase() == "table") {
+ var inputElements = ctrl.getElementsByTagName("input");
+ var lastInputElement =
inputElements[inputElements.length -1];
+ if (lastInputElement != null) {
+ ctrl = lastInputElement;
+ }
+ }
+ if (typeof(ctrl.focus) != "undefined" && ctrl.focus != null) {
+ ctrl.focus();
+ return true;
+ }
+ }
+ return false;
+}
+
+function IsInVisibleContainer(ctrl) {
+ if (typeof(ctrl.style) != "undefined" &&
+ ((typeof(ctrl.style.display) != "undefined" &&
ctrl.style.display == "none") ||
+ (typeof(ctrl.style.visibility) != "undefined" &&
ctrl.style.visibility == "hidden"))) {
+ return false;
+ }
+ else if (typeof(ctrl.parentNode) != "undefined" && ctrl.parentNode !=
null && ctrl.parentNode != ctrl) {
+ return IsInVisibleContainer(ctrl.parentNode);
+ }
+ return true;
+}
+
/*******************/
/* type converters */
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches