You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2018/10/23 14:29:45 UTC

[royale-asjs] branch develop updated: Jewel DateValidator

This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new 705774a  Jewel DateValidator
705774a is described below

commit 705774aec982302ab02176fc385db9d71b7669fa
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Tue Oct 23 16:29:37 2018 +0200

    Jewel DateValidator
---
 .../src/main/royale/FormsValidationPlayGround.mxml |   7 +
 .../Jewel/src/main/resources/jewel-manifest.xml    |   1 +
 .../jewel/beads/validators/CheckBoxValidator.as    |   7 +-
 .../{CheckBoxValidator.as => DateValidator.as}     | 188 ++++++++++-----------
 .../royale/jewel/beads/validators/FormValidator.as |   3 +-
 .../royale/jewel/beads/validators/Validator.as     |   2 +-
 6 files changed, 105 insertions(+), 103 deletions(-)

diff --git a/examples/royale/JewelExample/src/main/royale/FormsValidationPlayGround.mxml b/examples/royale/JewelExample/src/main/royale/FormsValidationPlayGround.mxml
index 8204843..feb92d1 100644
--- a/examples/royale/JewelExample/src/main/royale/FormsValidationPlayGround.mxml
+++ b/examples/royale/JewelExample/src/main/royale/FormsValidationPlayGround.mxml
@@ -59,6 +59,13 @@ limitations under the License.
 					<j:StringValidator required="3" autoTrim="true" requiredFieldError="Need more than 3 characters"/>
 				</j:beads>
 			</j:TextInput>
+			
+			<html:H4 text="Your born date"/>
+			<j:DateField>
+				<j:beads>
+					<j:DateValidator requiredFieldError="The value is not a valid date"/>
+				</j:beads>
+			</j:DateField>
 
 			<html:H4 text="Favorite movies (at least 2)"/>
 			<j:VGroup gap="3">
diff --git a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
index 11ef504..31ddb71 100644
--- a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
+++ b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
@@ -74,6 +74,7 @@
     <component id="Validator" class="org.apache.royale.jewel.beads.validators.Validator"/>
     <component id="FormValidator" class="org.apache.royale.jewel.beads.validators.FormValidator"/>
     <component id="StringValidator" class="org.apache.royale.jewel.beads.validators.StringValidator"/>
+    <component id="DateValidator" class="org.apache.royale.jewel.beads.validators.DateValidator"/>
     <component id="CheckBoxValidator" class="org.apache.royale.jewel.beads.validators.CheckBoxValidator"/>
     <component id="RadioButtonValidator" class="org.apache.royale.jewel.beads.validators.RadioButtonValidator"/>
 
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/CheckBoxValidator.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/CheckBoxValidator.as
index 457f1bb..9fec11a 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/CheckBoxValidator.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/CheckBoxValidator.as
@@ -46,7 +46,7 @@ package org.apache.royale.jewel.beads.validators
 			super()
 		}
 
-		       /**                         	
+		/**                         	
 		 *  @copy org.apache.royale.core.IBead#strand
 		 *
 		 *  @langversion 3.0
@@ -58,10 +58,7 @@ package org.apache.royale.jewel.beads.validators
 		override public function set strand(value:IStrand):void
 		{
 			super.strand = value;
-			COMPILE::JS
-			{
-				hostComponent.addEventListener(Event.CHANGE, validate, false);
-			}
+			hostComponent.addEventListener(Event.CHANGE, validate, false);
 		}
 
 
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/CheckBoxValidator.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/DateValidator.as
similarity index 70%
copy from frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/CheckBoxValidator.as
copy to frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/DateValidator.as
index 457f1bb..71aeb6c 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/CheckBoxValidator.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/DateValidator.as
@@ -1,95 +1,93 @@
-////////////////////////////////////////////////////////////////////////////////
-//
-//  Licensed to the Apache Software Foundation (ASF) under one or more
-//  contributor license agreements.  See the NOTICE file distributed with
-//  this work for additional information regarding copyright ownership.
-//  The ASF licenses this file to You under the Apache License, Version 2.0
-//  (the "License"); you may not use this file except in compliance with
-//  the License.  You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-//  Unless required by applicable law or agreed to in writing, software
-//  distributed under the License is distributed on an "AS IS" BASIS,
-//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-//  See the License for the specific language governing permissions and
-//  limitations under the License.
-//
-////////////////////////////////////////////////////////////////////////////////
-package org.apache.royale.jewel.beads.validators
-{
-	import org.apache.royale.core.IStrand;
-	import org.apache.royale.events.Event;
-	import org.apache.royale.jewel.CheckBox;
-
-	/**
-	 *  The CheckBoxValidator class is a specialty bead that can be used with
-	 *  Group control.
-	 *
-	 *  @langversion 3.0
-	 *  @playerversion Flash 10.2
-	 *  @playerversion AIR 2.6
-	 *  @productversion Royale 0.9.4
-	 */
-	public class CheckBoxValidator extends Validator
-	{
-		/**
-		 *  constructor.
-		 *
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion Royale 0.9.4
-		 */
-		public function CheckBoxValidator()
-		{
-			super()
-		}
-
-		       /**                         	
-		 *  @copy org.apache.royale.core.IBead#strand
-		 *
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion Royale 0.9.4
-		 *  @royaleignorecoercion org.apache.royale.events.IEventDispatcher
-		 */
-		override public function set strand(value:IStrand):void
-		{
-			super.strand = value;
-			COMPILE::JS
-			{
-				hostComponent.addEventListener(Event.CHANGE, validate, false);
-			}
-		}
-
-
-		/**
-		 *  Override of the base class validate() method to validate if selected.
-		 * 
-		 *  @langversion 3.0
-		 *  @playerversion Flash 10.2
-		 *  @playerversion AIR 2.6
-		 *  @productversion Royale 0.9.4
-		 */
-		override public function validate(event:Event = null):Boolean {
-			if (super.validate(event)) {
-				var selectedCount:int = 0;
-				var i:int = hostComponent.numElements;
-				while(--i > -1) {
-					var checkBox:CheckBox = hostComponent.getElementAt(i) as CheckBox;
-					if (!checkBox) continue;
-					if (checkBox.selected)
-						selectedCount++;
-				}
-				if (selectedCount < required) {
-					createErrorTip(requiredFieldError);
-				} else {
-					destroyErrorTip();
-				}	
-			}
-			return !isError;
-		}		
-	}
-}
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.jewel.beads.validators
+{
+    import org.apache.royale.core.IStrand;
+    import org.apache.royale.events.Event;
+    import org.apache.royale.jewel.DateField;
+
+    /**
+	 *  The DateValidator class is a specialty bead that can be used with
+	 *  Group control.
+	 *
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.4
+	 */
+	public class DateValidator extends Validator
+	{
+		/**
+		 *  constructor.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.4
+		 */
+		public function DateValidator()
+		{
+			super()
+		}
+
+        /**                         	
+		 *  @copy org.apache.royale.core.IBead#strand
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.4
+		 *  @royaleignorecoercion org.apache.royale.events.IEventDispatcher
+		 */
+		override public function set strand(value:IStrand):void
+		{
+			super.strand = value;
+			hostComponent.addEventListener(Event.CHANGE, validate, false);
+		}
+
+		private function isValidDate(d:*):Boolean
+		{
+			return (d is Date) && !isNaN(d);
+		}
+
+        /**
+		 *  Override of the base class validate() method to validate if selected.
+		 * 
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.4
+		 */
+		override public function validate(event:Event = null):Boolean {
+			var df:DateField = hostComponent as DateField;
+			if (super.validate(event))
+            {
+				trace("this is true no validation func");
+				if (!isValidDate(df.selectedDate)) {
+			trace("is not a valid date");
+					createErrorTip(requiredFieldError);
+				} else {
+			trace("is valid date");
+					destroyErrorTip();
+				}	
+			}
+			return !isError;
+		}
+    }
+}
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/FormValidator.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/FormValidator.as
index 5cc6b25..e3eec2f 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/FormValidator.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/FormValidator.as
@@ -22,8 +22,7 @@ package org.apache.royale.jewel.beads.validators
 	import org.apache.royale.events.Event;
 	import org.apache.royale.events.IEventDispatcher;
 	import org.apache.royale.jewel.Group;
-    import org.apache.royale.jewel.Snackbar;
-	import org.apache.royale.core.IChild;
+	import org.apache.royale.jewel.Snackbar;
 
 	/**
 	 *  The FormValidator class is a specialty bead that can be used with
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/Validator.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/Validator.as
index 769e766..383ef14 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/Validator.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/Validator.as
@@ -79,9 +79,9 @@ package org.apache.royale.jewel.beads.validators
 		 */
 		public function set strand(value:IStrand):void
 		{
+			hostComponent = value as UIBase;
 			COMPILE::JS
 			{
-				hostComponent = value as UIBase;
 				hostClassList = hostComponent.positioner.classList;
 			}
 		}