* Authors:
* Chris Toshok (toshok@ximian.com)
*
- * (c) 2005 Novell, Inc. (http://www.novell.com)
+ * (c) 2005-2009 Novell, Inc. (http://www.novell.com)
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
webForm.ValidatorOnLoad = function ()
{
- if (typeof (this.Page_ValidationSummaries) != 'undefined' && this.Page_ValidationSummaries != null) {
- this.have_validation_summaries = true;
- for (var v = 0; v < this.Page_ValidationSummaries.length; v++) {
- var vs = this.Page_ValidationSummaries [v];
- if (vs.getAttribute ("validationgroup") == null)
- vs.setAttribute ("validationgroup", "");
- }
- }
-
- for (var v = 0; v < this.Page_Validators.length; v++) {
- var vo = this.Page_Validators [v];
-
- if (vo.getAttribute ("isvalid") == null)
- vo.setAttribute ("isvalid", "true");
-
- if (vo.getAttribute ("enabled") == null)
- vo.setAttribute ("enabled", "true");
-
- if (vo.getAttribute ("validationgroup") == null)
- vo.setAttribute ("validationgroup", "");
+ if (typeof (webForm.Page_ValidationSummaries) != 'undefined' && webForm.Page_ValidationSummaries != null) {
+ webForm.have_validation_summaries = true;
+ }
+
+ if (typeof (webForm.Page_Validators) != 'undefined' || webForm.Page_Validators != null) {
+ 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;
+ else
+ vo._isvalid = true;
+
+ if (typeof(vo.enabled) == "string" && vo.enabled == "False")
+ vo._enabled = false;
+ else
+ vo._enabled = true;
+
+ if (typeof(vo.evaluationfunction) == "string")
+ vo.evaluationfunction = webForm [vo.evaluationfunction];
+ }
}
-
- this.Page_ValidationActive = true;
+
+ webForm.Page_ValidationActive = true;
}
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 = vs.getAttribute ("headertext");
- if (header == null)
- header = "";
+ var header = "";
+ if(typeof(vs.headertext)=="string")
+ header = vs.headertext;
- attr = vs.getAttribute ("showsummary");
- if (attr == null || attr.toLowerCase() == "true") {
- var displaymode = vs.getAttribute ("displaymode");
- if (displaymode == null) displaymode = "Bulleted";
+ if (vs.showsummary != "False") {
+ if (typeof(vs.displaymode) != "string")
+ vs.displaymode = "BulletList";
var html = "";
- if (displaymode == "List") {
+ if (vs.displaymode == "List") {
list_pre = "";
list_post = "";
item_pre = "";
item_post = "<br>";
}
- else if (displaymode == "SingleParagraph") {
+ else if (vs.displaymode == "SingleParagraph") {
list_pre = "";
list_post = "<br>";
item_pre = "";
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.getAttribute ("isvalid").toLowerCase() == "false") {
- var text = this.ValidatorGetErrorMessage (vo);
+ if (!vo._isvalid) {
+ var text = vo.errormessage;
if (text != null && text != "") {
html += item_pre + text + item_post;
}
vs.style.display = "block";
}
- attr = vs.getAttribute ("showmessagebox");
- if (attr != null && attr.toLowerCase() == "true") {
+ 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.getAttribute ("isvalid").toLowerCase() == "false") {
- var text = this.ValidatorGetErrorMessage (vo);
+ if (!vo._isvalid) {
+ var text = vo.errormessage;
if (text != null && text != "") {
v_contents += "-" + text + "\n";
}
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 (el == null)
+ return null;
/* if the element has a 'value' attribute, return it */
if (typeof (el.value) != 'undefined' && el.value != null) {
if (typeof (el.selectedIndex) != 'undefined') {
return el.options[el.selectedIndex].value;
}
-
- return this.ValidatorGetValueRecursive(el);
+
+ return webForm.ValidatorGetValueRecursive(el);
}
webForm.ValidatorGetValueRecursive = function (el)
if (el.type != "radio" || el.checked == true) return el.value;
}
for (var i = 0; i<el.childNodes.length; i++) {
- var val = this.ValidatorGetValueRecursive(el.childNodes[i]);
+ var val = webForm.ValidatorGetValueRecursive(el.childNodes[i]);
if (val != "") return val;
}
return "";
webForm.ValidatorTrim = function (s)
{
+ if (s == null)
+ return null;
+
s = s.replace (/^\s+/g, "");
s = s.replace (/\s+$/g, "");
webForm.Page_ClientValidate = function (group)
{
- this.validation_result = true;
+ webForm.validation_result = true;
/* clear out the existing text from all our summaries */
- if (this.have_validation_summaries) {
- for (var vi = 0; vi < this.Page_ValidationSummaries.length; vi++) {
- var vs = this.Page_ValidationSummaries[vi];
+ if (webForm.have_validation_summaries) {
+ for (var vi = 0; vi < webForm.Page_ValidationSummaries.length; vi++) {
+ var vs = webForm.Page_ValidationSummaries[vi];
vs.style.display = "none";
vs.innerHTML = "";
}
}
var invalidControlHasBeenFocused = false;
- for (var v = 0; v < this.Page_Validators.length; v++) {
- var vo = this.Page_Validators [v];
- var evalfunc = this[vo.getAttribute ("evaluationfunction")];
- var result = false;
-
- if (vo.getAttribute ("enabled").toLowerCase() == "false" || !this.IsValidationGroupMatch(vo, group)) {
- result = true;
- this.ValidatorSucceeded (vo);
- }
- else {
- result = evalfunc.call (this, vo);
- }
+ if (typeof (webForm.Page_Validators) != 'undefined' || webForm.Page_Validators != null) {
+ for (var v = 0; v < webForm.Page_Validators.length; v++) {
+ var vo = webForm.Page_Validators [v];
+ var evalfunc = vo.evaluationfunction;
+ var result = false;
+ var el = webForm.GetElement (vo.controltovalidate);
+
+ if (el == null) {
+ result = true;
+ webForm.ValidatorSucceeded (vo);
+ } else if (!vo._enabled || !webForm.IsValidationGroupMatch(vo, group)) {
+ result = true;
+ webForm.ValidatorSucceeded (vo);
+ } else {
+ result = evalfunc.call (this, vo);
+ }
- if (!result) {
- this.validation_result = false;
- if (!invalidControlHasBeenFocused && typeof(vo.focusOnError) == "string" && vo.focusOnError == "t") {
- invalidControlHasBeenFocused = this.ValidatorSetFocus(vo);
+ if (!result) {
+ webForm.validation_result = false;
+ if (!invalidControlHasBeenFocused && typeof(vo.focusOnError) == "string" && vo.focusOnError == "t") {
+ invalidControlHasBeenFocused = webForm.ValidatorSetFocus(vo);
+ }
}
- }
- vo.setAttribute("isvalid", result ? "true" : "false");
+ vo._isvalid = result;
+ }
+ webForm.ValidationSummaryOnSubmit(group);
}
- this.ValidationSummaryOnSubmit(group);
- return this.validation_result;
+
+ return webForm.validation_result;
}
webForm.IsValidationGroupMatch = function (vo, group) {
- var valGroup = vo.getAttribute ("validationgroup");
+ var valGroup = "";
+ if (typeof(vo.validationGroup) == "string")
+ valGroup = vo.validationGroup;
if ((typeof(group) == "undefined") || (group == null)) {
return (valGroup == "");
}
}
webForm.ValidatorSetFocus = function (val) {
- var ctrl = this.GetElement(val.getAttribute ("controltovalidate"));
+ var ctrl = webForm.GetElement(val.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) &&
- (this.IsInVisibleContainer(ctrl))) {
+ (webForm.IsInVisibleContainer(ctrl))) {
if (ctrl.tagName.toLowerCase() == "table") {
var inputElements = ctrl.getElementsByTagName("input");
var lastInputElement = inputElements[inputElements.length -1];
return false;
}
else if (typeof(ctrl.parentNode) != "undefined" && ctrl.parentNode != null && ctrl.parentNode != ctrl) {
- return this.IsInVisibleContainer(ctrl.parentNode);
+ return webForm.IsInVisibleContainer(ctrl.parentNode);
}
return true;
}
webForm.ToInteger = function (s, validator)
{
- if ((v = parseInt(s, 10)) != s - 0)
+ if (s.match(/^\s*[-\+]?\d+\s*$/) == null)
return null;
- else
- return v;
+ var v = parseInt(s, 10);
+ return (isNaN(v) ? null : v);
}
webForm.ToString = function (s, validator)
webForm.ToDate = function (s, validator)
{
- if (!this.HaveRegexp ())
+ if (!webForm.HaveRegexp ())
return null;
var m, day, month, year;
var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-/]|\\. ?)(\\d{1,2})\\4(\\d{1,2})\\s*$");
if (m != null && (m[2].length == 4 || validator.dateorder == "ymd")) {
day = m[6];
month = m[5];
- year = (m[2].length == 4) ? m[2] : this.GetFullYear(parseInt(m[3], 10), validator.cutoffyear)
+ year = (m[2].length == 4) ? m[2] : webForm.GetFullYear(parseInt(m[3], 10), validator.cutoffyear)
}
else {
if (validator.dateorder == "ymd") return null;
day = m[1];
month = m[3];
}
- year = (m[5].length == 4) ? m[5] : this.GetFullYear(parseInt(m[6], 10), validator.cutoffyear)
+ year = (m[5].length == 4) ? m[5] : webForm.GetFullYear(parseInt(m[6], 10), validator.cutoffyear)
}
month -= 1;
var date = new Date(year, month, day);
webForm.ToCurrency = function (s, validator)
{
- if (!this.HaveRegexp ())
+ if (!webForm.HaveRegexp ())
return null;
var hasDigits = (validator.digits > 0);
webForm.CompareValidatorEvaluateIsValid = function (validator)
{
- var ControlToCompare = validator.getAttribute ("controltocompare");
- var ValueToCompare = validator.getAttribute ("valuetocompare");
- var Operator = validator.getAttribute ("operator").toLowerCase();
- var ControlToValidate = validator.getAttribute ("controltovalidate");
- var DataType = validator.getAttribute ("datatype");
+ var Operator = validator.operator.toLowerCase();
+ var ControlToValidate = validator.controltovalidate;
+ var DataType = validator.type;
- var ctrl_value = this.ValidatorTrim (this.ValidatorGetValue (ControlToValidate));
- if (ctrl_value == "") {
- this.ValidatorSucceeded (validator);
+ var ctrl_value = webForm.ValidatorGetValue (ControlToValidate);
+ if (webForm.ValidatorTrim (ctrl_value) == "") {
+ webForm.ValidatorSucceeded (validator);
return true;
}
- var compare = (ControlToCompare != null && ControlToCompare != "") ? this.ValidatorTrim (this.ValidatorGetValue (ControlToCompare)) : 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;
}
+
+ if (Operator == "datatypecheck") {
+ webForm.ValidatorSucceeded (validator);
+ return true;
+ }
- var right = compare != null ? this.Convert (compare, DataType, validator) : null;
+ var compare = "";
+ if (typeof(validator.controltocompare) == "string" && document.getElementById(validator.controltocompare))
+ compare = webForm.ValidatorGetValue(validator.controltocompare);
+ else if (typeof(validator.valuetocompare) == "string")
+ compare = validator.valuetocompare;
+
+ var right = compare != null ? webForm.Convert (compare, DataType, validator) : null;
if (right == null) {
- this.ValidatorSucceeded (validator);
+ webForm.ValidatorSucceeded (validator);
return true;
}
}
if (result == false) {
- this.ValidatorFailed (validator);
+ webForm.ValidatorFailed (validator);
return false;
}
else {
- this.ValidatorSucceeded (validator);
+ webForm.ValidatorSucceeded (validator);
return true;
}
}
webForm.RangeValidatorEvaluateIsValid = function (validator)
{
- var ControlToValidate = validator.getAttribute ("controltovalidate");
- var DataType = validator.getAttribute ("datatype");
+ 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.getAttribute ("minimumvalue"), DataType, validator);
- var MaximumValue = this.Convert (validator.getAttribute ("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;
}
}
webForm.RegularExpressionValidatorEvaluateIsValid = function (validator)
{
- var ValidationExpression = validator.getAttribute ("validationexpression");
- var ControlToValidate = validator.getAttribute ("controltovalidate");
+ 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);
+ if (match == null || match[0] != ctrl_value) {
+ webForm.ValidatorFailed (validator);
return false;
}
else {
- this.ValidatorSucceeded (validator);
+ webForm.ValidatorSucceeded (validator);
return true;
}
}
webForm.RequiredFieldValidatorEvaluateIsValid = function (validator)
{
- var InitialValue = validator.getAttribute ("initialvalue");
- var ControlToValidate = validator.getAttribute ("controltovalidate");
-
- var ctrl_value = this.ValidatorTrim (this.ValidatorGetValue (ControlToValidate));
+ var InitialValue = validator.initialvalue;
+ var ControlToValidate = validator.controltovalidate;
- if (ctrl_value == this.ValidatorTrim (InitialValue)) {
- this.ValidatorFailed (validator);
+ var ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate));
+
+ if (ctrl_value == webForm.ValidatorTrim (InitialValue)) {
+ webForm.ValidatorFailed (validator);
return false;
}
else {
- this.ValidatorSucceeded (validator);
+ webForm.ValidatorSucceeded (validator);
return true;
}
}
webForm.CustomValidatorEvaluateIsValid = function (validator)
{
- var InitialValue = validator.getAttribute ("initialvalue");
- var ControlToValidate = validator.getAttribute ("controltovalidate");
+ var ControlToValidate = validator.controltovalidate;
+ var evaluationfunc = validator.clientvalidationfunction;
+ var ctrl_value;
- if (!ControlToValidate) {
- this.ValidatorSucceeded (validator);
- return true;
- }
-
- var evaluationfunc = validator.getAttribute ("clientvalidationfunction");
+ if (ControlToValidate) {
+ ctrl_value = webForm.ValidatorTrim (webForm.ValidatorGetValue (ControlToValidate));
- var ctrl_value = this.ValidatorTrim (this.ValidatorGetValue (ControlToValidate));
-
- if ((ctrl_value.length == 0) && ((typeof(validator.validateemptytext) != "string") || (validator.validateemptytext != "true"))) {
- this.ValidatorSucceeded (validator);
+ if ((ctrl_value.length == 0) && ((typeof(validator.validateemptytext) != "string") || (validator.validateemptytext != "true"))) {
+ webForm.ValidatorSucceeded (validator);
return true;
- }
-
+ }
+ } else
+ ctrl_value = "";
var result = true;
if (evaluationfunc && evaluationfunc != "") {
}
if (result) {
- this.ValidatorSucceeded (validator);
+ webForm.ValidatorSucceeded (validator);
return true;
}
else {
- this.ValidatorFailed (validator);
+ webForm.ValidatorFailed (validator);
return false;
}
}
webForm.ValidatorUpdateDisplay = function (v, valid)
{
- var display = v.getAttribute ("display");
+ var display = v.display;
/* for validators that aren't displayed, do nothing */
if (display == "None") {
}
}
-webForm.ValidatorGetErrorMessage = function (v)
-{
- var text = v.getAttribute ("errormessage");
- if (text == null || text == "")
- text = v.getAttribute ("text");
- if (text == null)
- text = "";
- return text;
-}
-
-webForm.ValidatorGetText = function (v)
-{
- var text = v.getAttribute ("text");
- if (text == null || text == "")
- text = v.getAttribute ("errormessage");
- if (text == null)
- text = "";
- return text;
-}
-
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)
((document.all) ? document.all [id] : null);
return x;
}
-}
\ No newline at end of file
+
+
+}