click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r956618 - in /click/trunk/click: extras/src/META-INF/resources/click/colorpicker/colorpicker.js extras/src/META-INF/resources/click/extras-control.js framework/src/META-INF/resources/click/control.js
Date Mon, 21 Jun 2010 15:17:26 GMT
Author: sabob
Date: Mon Jun 21 15:17:26 2010
New Revision: 956618

URL: http://svn.apache.org/viewvc?rev=956618&view=rev
Log:
fixed javascript validation to add/remove element class instead of style color. CLK-700

Modified:
    click/trunk/click/extras/src/META-INF/resources/click/colorpicker/colorpicker.js
    click/trunk/click/extras/src/META-INF/resources/click/extras-control.js
    click/trunk/click/framework/src/META-INF/resources/click/control.js

Modified: click/trunk/click/extras/src/META-INF/resources/click/colorpicker/colorpicker.js
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/META-INF/resources/click/colorpicker/colorpicker.js?rev=956618&r1=956617&r2=956618&view=diff
==============================================================================
--- click/trunk/click/extras/src/META-INF/resources/click/colorpicker/colorpicker.js (original)
+++ click/trunk/click/extras/src/META-INF/resources/click/colorpicker/colorpicker.js Mon Jun
21 15:17:26 2010
@@ -54,15 +54,15 @@ function validateColorPicker(id, require
         var value = field.value;
         if(value.length == 0){
             if(required){
-                setFieldErrorColor(field);
+                Click.setFieldErrorClass(field);
                 return msgs[0];
             }
         } else if(!field.value.match(new RegExp("^#[a-fA-F0-9]{3}([a-fA-F0-9]{3})?$"))){
-            setFieldErrorColor(field);
+            Click.setFieldErrorClass(field);
             return msgs[1];
         }
 
-        setFieldValidColor(field);
+        Click.setFieldValidClass(field);
         return null;
 
     } else {

Modified: click/trunk/click/extras/src/META-INF/resources/click/extras-control.js
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/META-INF/resources/click/extras-control.js?rev=956618&r1=956617&r2=956618&view=diff
==============================================================================
--- click/trunk/click/extras/src/META-INF/resources/click/extras-control.js (original)
+++ click/trunk/click/extras/src/META-INF/resources/click/extras-control.js Mon Jun 21 15:17:26
2010
@@ -50,7 +50,7 @@ function validateCreditCardField(id, typ
 			
 			var length = value.length;
 			if(length < 13){
-				setFieldErrorColor(field);
+				Click.setFieldErrorClass(field);
 				return msgs[3];
 			}
 			
@@ -75,13 +75,13 @@ function validateCreditCardField(id, typ
 			}
 			
 			if (!isValid) {
-				setFieldErrorColor(field);
+				Click.setFieldErrorClass(field);
 				return msgs[3];
 			}
 		}
 		
 		// no error
-		setFieldValidColor(field);
+		Click.setFieldValidClass(field);
 		return null;
 	}
 }
@@ -99,22 +99,22 @@ function validateEmailField (id, require
 			var index = value.indexOf("@");
 			
 			if (index < 1 || index == length - 1) {
-				setFieldErrorColor(field);
+				Click.setFieldErrorClass(field);
 				return msgs[3];
 			}
 	
 			if (!isLetterOrDigit(value.charAt(0))) {
-				setFieldErrorColor(field);
+				Click.setFieldErrorClass(field);
 				return msgs[3];
 			}
 	
 			if (!isLetterOrDigit(value.charAt(length - 1))) {
-				setFieldErrorColor(field);
+				Click.setFieldErrorClass(field);
 				return msgs[3];
 			}
 		}
 	}
-	setFieldValidColor(field);
+	Click.setFieldValidClass(field);
 	return null;
 }
 
@@ -124,20 +124,20 @@ function validateNumberField(id, require
 		var value = field.value;
 		if (value.length == 0) {
 			if(required){
-				setFieldErrorColor(field);
+				Click.setFieldErrorClass(field);
 				return msgs[0];
 			}
 		} else {
 			if (value > maxValue){
-				setFieldErrorColor(field);
+				Click.setFieldErrorClass(field);
 				return msgs[2];
 			} else if (value < minValue){
-				setFieldErrorColor(field);
+				Click.setFieldErrorClass(field);
 				return msgs[1];
 			}
 		}
 		
-		setFieldValidColor(field);
+		Click.setFieldValidClass(field);
 		return null;
 		
 	} else {
@@ -150,12 +150,12 @@ function validatePickList(id, required, 
 	if(field){
 		if (field.options.length == 0) {
 			if(required){
-				setFieldErrorColor(field);
+				Click.setFieldErrorClass(field);
 				return msgs[0];
 			}
 		}
 		
-		setFieldValidColor(field);
+		Click.setFieldValidClass(field);
 		return null;
 		
 	} else {
@@ -170,10 +170,10 @@ function validateRegexField(id, required
 	} else {
 		var field = document.getElementById(id);
 		if (field.value.length == 0 || field.value.match(new RegExp(regex))) {
-			setFieldValidColor(field);
+			Click.setFieldValidClass(field);
 			return null;
 		} else {
-			setFieldErrorColor(field);
+			Click.setFieldErrorClass(field);
 			return msgs[3];
 		}
 	}
@@ -259,12 +259,12 @@ function pickListMoveItem(from, to, valu
  *
  * @return false to prevent the link default action
  */
-Click.submitLinkAction = function(link, formName) {
+Click.submitLinkAction = function(link, formId) {
   var params=Click.getUrlParams(link.href);
   if (params == null) {
       return false;
   }
-  var form = document.getElementById(formName);
+  var form = document.getElementById(formId);
   if(form == null) {
       return false;
   }

Modified: click/trunk/click/framework/src/META-INF/resources/click/control.js
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/META-INF/resources/click/control.js?rev=956618&r1=956617&r2=956618&view=diff
==============================================================================
--- click/trunk/click/framework/src/META-INF/resources/click/control.js (original)
+++ click/trunk/click/framework/src/META-INF/resources/click/control.js Mon Jun 21 15:17:26
2010
@@ -212,13 +212,39 @@ function trim(str) {
       return str;
 }
 
+Click.hasClass=function(element,cls){
+    var className=element.className;
+    if(className) {
+        return new RegExp('\\b'+cls+'\\b').test(className);
+    }
+    return false;
+}
+
+Click.addClass=function(element,cls){
+    if(!Click.hasClass(element,cls)) {
+        element.className += element.className ? ' ' + cls : cls;
+    }
+}
+
+Click.removeClass=function(element,cls){
+    var className=element.className;
+    if(!className) return;
+
+    if(className.indexOf(' ')<0) {
+        element.className='';
+        return;
+    }
+
+    var rep = new RegExp('(^|\\s)' + cls + '(?:\\s|$)');
+    element.className = className.replace(rep, '$1');
+}
 
-function setFieldValidColor(field) {
-    field.style.background = 'white';
+Click.setFieldValidClass=function(field) {
+    Click.removeClass(field,'error');
 }
 
-function setFieldErrorColor(field) {
-    field.style.background = '#FFFF80';
+Click.setFieldErrorClass=function(field) {
+    Click.addClass(field,'error');
 }
 
 function validateTextField(id, required, minLength, maxLength, msgs) {
@@ -227,23 +253,23 @@ function validateTextField(id, required,
         var value = trim(field.value);
         if (required) {
             if (value.length == 0) {
-                setFieldErrorColor(field);
+                Click.setFieldErrorClass(field);
                 return msgs[0];
             }
         }
         if (required && minLength > 0) {
             if (value.length < minLength) {
-                setFieldErrorColor(field);
+                Click.setFieldErrorClass(field);
                 return msgs[1];
             }
         }
         if (maxLength > 0) {
             if (value.length > maxLength) {
-                setFieldErrorColor(field);
+                Click.setFieldErrorClass(field);
                 return msgs[2];
             }
         }
-        setFieldValidColor(field);
+        Click.setFieldValidClass(field);
         return null;
     } else {
         return 'Field ' + id + ' not found.';
@@ -271,10 +297,10 @@ function validateSelect(id, defaultValue
         if (required) {
             var value = field.value;
             if (value != defaultValue) {
-                setFieldValidColor(field);
+                Click.setFieldValidClass(field);
                 return null;
             } else {
-                setFieldErrorColor(field);
+                Click.setFieldErrorClass(field);
                 return msgs[0];
             }
         }
@@ -304,7 +330,7 @@ function validateFileField(id, required,
         var value = trim(field.value);
         if (required) {
             if (value.length == 0) {
-                setFieldErrorColor(field);
+                Click.setFieldErrorClass(field);
                 return msgs[0];
             }
         }



Mime
View raw message