From 75b9a8988eb31b43fd99e83648ef6ae0092ef3fa Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Fri, 28 Sep 2007 23:51:55 +0000 Subject: [PATCH] 2007-09-29 Marek Habersack * WebUIValidation_2.0.js: replace all the ocurrences of 'this' with 'webForm'. The reason for such change is that under certain circumstances the function may be called on an object which is not the original webForm to which the function was assigned. This happens, for instance, in the AJAX Control Toolkit which wraps the ValidatorGetValue function with its own version and calls the original function on a Function object, so 'this' in that instance becomes a 'function()' and not the original 'Window' object. svn path=/trunk/mcs/; revision=86622 --- mcs/class/System.Web/resources/ChangeLog | 11 ++ .../resources/WebUIValidation_2.0.js | 142 +++++++++--------- 2 files changed, 83 insertions(+), 70 deletions(-) diff --git a/mcs/class/System.Web/resources/ChangeLog b/mcs/class/System.Web/resources/ChangeLog index 3177a60534d..a338b83b972 100644 --- a/mcs/class/System.Web/resources/ChangeLog +++ b/mcs/class/System.Web/resources/ChangeLog @@ -1,3 +1,14 @@ +2007-09-29 Marek Habersack + + * WebUIValidation_2.0.js: replace all the ocurrences of 'this' with + 'webForm'. The reason for such change is that under certain + circumstances the function may be called on an object which is not + the original webForm to which the function was assigned. This + happens, for instance, in the AJAX Control Toolkit which wraps the + ValidatorGetValue function with its own version and calls the + original function on a Function object, so 'this' in that instance + becomes a 'function()' and not the original 'Window' object. + 2007-08-30 Igor Zelmanovich * WebUIValidation_2.0.js: diff --git a/mcs/class/System.Web/resources/WebUIValidation_2.0.js b/mcs/class/System.Web/resources/WebUIValidation_2.0.js index 845b129bc62..b317a7b788a 100644 --- a/mcs/class/System.Web/resources/WebUIValidation_2.0.js +++ b/mcs/class/System.Web/resources/WebUIValidation_2.0.js @@ -39,12 +39,12 @@ webForm.HaveRegexp = function () webForm.ValidatorOnLoad = function () { - if (typeof (this.Page_ValidationSummaries) != 'undefined' && this.Page_ValidationSummaries != null) { - this.have_validation_summaries = true; + if (typeof (webForm.Page_ValidationSummaries) != 'undefined' && webForm.Page_ValidationSummaries != null) { + webForm.have_validation_summaries = true; } - for (var v = 0; v < this.Page_Validators.length; v++) { - var vo = this.Page_Validators [v]; + for (var v = 0; v < webForm.Page_Validators.length; v++) { + var vo = webForm.Page_Validators [v]; if (typeof(vo.isvalid) == "string" && vo.isvalid == "False") vo.isvalid = false; @@ -59,7 +59,7 @@ webForm.ValidatorOnLoad = function () vo.evaluationfunction = this [vo.evaluationfunction]; } - this.Page_ValidationActive = true; + webForm.Page_ValidationActive = true; } webForm.validation_result = true; @@ -67,12 +67,12 @@ webForm.validation_result = true; webForm.ValidationSummaryOnSubmit = function (group) { /* handle validation summaries here */ - if (this.validation_result == false && this.have_validation_summaries) { + if (webForm.validation_result == false && webForm.have_validation_summaries) { - for (var vi = 0; vi < this.Page_ValidationSummaries.length; vi++) { - var vs = this.Page_ValidationSummaries[vi]; + for (var vi = 0; vi < webForm.Page_ValidationSummaries.length; vi++) { + var vs = webForm.Page_ValidationSummaries[vi]; - if(this.IsValidationGroupMatch(vs, group)) { + if(webForm.IsValidationGroupMatch(vs, group)) { var header = ""; if(typeof(vs.headertext)=="string") @@ -105,8 +105,8 @@ webForm.ValidationSummaryOnSubmit = function (group) html += header; html += list_pre; - for (var v = 0; v < this.Page_Validators.length; v++) { - var vo = this.Page_Validators [v]; + for (var v = 0; v < webForm.Page_Validators.length; v++) { + var vo = webForm.Page_Validators [v]; if (!vo.isvalid) { var text = vo.errormessage; @@ -124,8 +124,8 @@ webForm.ValidationSummaryOnSubmit = function (group) if (vs.showmessagebox == "True") { var v_contents = ""; - for (var v = 0; v < this.Page_Validators.length; v++) { - var vo = this.Page_Validators [v]; + for (var v = 0; v < webForm.Page_Validators.length; v++) { + var vo = webForm.Page_Validators [v]; if (!vo.isvalid) { var text = vo.errormessage; @@ -148,14 +148,14 @@ webForm.ValidationSummaryOnSubmit = function (group) webForm.ValidatorCommonOnSubmit = function () { - var rv = this.validation_result; - this.validation_result = true; + var rv = webForm.validation_result; + webForm.validation_result = true; return rv; } webForm.ValidatorGetValue = function (controlname) { - var el = this.GetElement (controlname); + var el = webForm.GetElement (controlname); /* if the element has a 'value' attribute, return it */ if (typeof (el.value) != 'undefined' && el.value != null) { @@ -167,8 +167,8 @@ webForm.ValidatorGetValue = function (controlname) if (typeof (el.selectedIndex) != 'undefined') { return el.options[el.selectedIndex].value; } - - return this.ValidatorGetValueRecursive(el); + + return webForm.ValidatorGetValueRecursive(el); } webForm.ValidatorGetValueRecursive = function (el) @@ -177,7 +177,7 @@ webForm.ValidatorGetValueRecursive = function (el) if (el.type != "radio" || el.checked == true) return el.value; } for (var i = 0; i 0); @@ -375,26 +375,26 @@ webForm.CompareValidatorEvaluateIsValid = function (validator) var ControlToValidate = validator.controltovalidate; var DataType = validator.type; - var ctrl_value = this.ValidatorTrim (this.ValidatorGetValue (ControlToValidate)); + var ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate)); if (ctrl_value == "") { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } var compare = ""; if (typeof(validator.controltocompare) == "string" && document.getElementById(validator.controltocompare)) - compare = this.ValidatorTrim(this.ValidatorGetValue(val.controltocompare)); + compare = webForm.ValidatorTrim(webForm.ValidatorGetValue(val.controltocompare)); else if (typeof(validator.valuetocompare) == "string") compare = validator.valuetocompare; - var left = this.Convert (ctrl_value, DataType, validator); + var left = webForm.Convert (ctrl_value, DataType, validator); if (left == null) { - this.ValidatorFailed (validator); + webForm.ValidatorFailed (validator); return false; } - var right = compare != null ? this.Convert (compare, DataType, validator) : null; + var right = compare != null ? webForm.Convert (compare, DataType, validator) : null; if (right == null) { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } @@ -420,11 +420,11 @@ webForm.CompareValidatorEvaluateIsValid = function (validator) } if (result == false) { - this.ValidatorFailed (validator); + webForm.ValidatorFailed (validator); return false; } else { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } } @@ -434,22 +434,22 @@ webForm.RangeValidatorEvaluateIsValid = function (validator) var ControlToValidate = validator.controltovalidate; var DataType = validator.type; - var ctrl_value = this.ValidatorTrim (this.ValidatorGetValue (ControlToValidate)); + var ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate)); if (ctrl_value == "") { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } - var MinimumValue = this.Convert (validator.minimumvalue, DataType, validator); - var MaximumValue = this.Convert (validator.maximumvalue, DataType, validator); - var val = this.Convert (ctrl_value, DataType, validator); + var MinimumValue = webForm.Convert (validator.minimumvalue, DataType, validator); + var MaximumValue = webForm.Convert (validator.maximumvalue, DataType, validator); + var val = webForm.Convert (ctrl_value, DataType, validator); if (val == null || val < MinimumValue || val > MaximumValue) { - this.ValidatorFailed (validator); + webForm.ValidatorFailed (validator); return false; } else { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } } @@ -459,24 +459,24 @@ webForm.RegularExpressionValidatorEvaluateIsValid = function (validator) var ValidationExpression = validator.validationexpression; var ControlToValidate = validator.controltovalidate; - var ctrl_value = this.ValidatorTrim (this.ValidatorGetValue (ControlToValidate)); + var ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate)); if (ctrl_value == "") { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } - if (!this.HaveRegexp ()) + if (!webForm.HaveRegexp ()) return false; var r = new RegExp (ValidationExpression); match = r.exec (ctrl_value); if (match == null || match[0] == "") { - this.ValidatorFailed (validator); + webForm.ValidatorFailed (validator); return false; } else { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } } @@ -486,14 +486,14 @@ webForm.RequiredFieldValidatorEvaluateIsValid = function (validator) var InitialValue = validator.initialvalue; var ControlToValidate = validator.controltovalidate; - var ctrl_value = this.ValidatorTrim (this.ValidatorGetValue (ControlToValidate)); + var ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate)); - if (ctrl_value == this.ValidatorTrim (InitialValue)) { - this.ValidatorFailed (validator); + if (ctrl_value == webForm.ValidatorTrim (InitialValue)) { + webForm.ValidatorFailed (validator); return false; } else { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } } @@ -503,16 +503,16 @@ webForm.CustomValidatorEvaluateIsValid = function (validator) var ControlToValidate = validator.controltovalidate; if (!ControlToValidate) { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } var evaluationfunc = validator.clientvalidationfunction; - var ctrl_value = this.ValidatorTrim (this.ValidatorGetValue (ControlToValidate)); + var ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate)); if ((ctrl_value.length == 0) && ((typeof(validator.validateemptytext) != "string") || (validator.validateemptytext != "true"))) { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } @@ -525,11 +525,11 @@ webForm.CustomValidatorEvaluateIsValid = function (validator) } if (result) { - this.ValidatorSucceeded (validator); + webForm.ValidatorSucceeded (validator); return true; } else { - this.ValidatorFailed (validator); + webForm.ValidatorFailed (validator); return false; } } @@ -563,12 +563,12 @@ webForm.ValidatorUpdateDisplay = function (v, valid) webForm.ValidatorFailed = function (v) { - this.ValidatorUpdateDisplay (v, false); + webForm.ValidatorUpdateDisplay (v, false); } webForm.ValidatorSucceeded = function (v) { - this.ValidatorUpdateDisplay (v, true); + webForm.ValidatorUpdateDisplay (v, true); } webForm.GetElement = function (id) @@ -577,4 +577,6 @@ webForm.GetElement = function (id) ((document.all) ? document.all [id] : null); return x; } + + } \ No newline at end of file -- 2.25.1