You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by gr...@apache.org on 2019/01/19 03:46:48 UTC

[royale-asjs] branch develop updated: Added support for explicitly removing errorTips. -Provided a utility function for this at individual Validator level (also required for subclasses outside package) -Updated Formvalidator to ignore non-visible items by default (could add support for non-visible inclusions if required) -Updated Formvalidator to iterate removal of errorTips -Updated TourDeJewel PopUpPlayGround example to remove error tips when form popup is closed @todo: remove error tips from Forms and Validation example whe [...]

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

gregdove 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 b804a9f  Added support for explicitly removing errorTips. -Provided a utility function for this at individual Validator level (also required for subclasses outside package) -Updated Formvalidator to ignore non-visible items by default (could add support for non-visible inclusions if required) -Updated Formvalidator to iterate removal of errorTips -Updated TourDeJewel PopUpPlayGround example to remove error tips when form popup is closed @todo: remove error tips from Forms and Val [...]
b804a9f is described below

commit b804a9f91ea857db281cf694701c55c545bbe26d
Author: greg-dove <gr...@gmail.com>
AuthorDate: Sat Jan 19 16:44:44 2019 +1300

    Added support for explicitly removing errorTips.
    -Provided a utility function for this at individual Validator level (also required for subclasses outside package)
    -Updated Formvalidator to ignore non-visible items by default (could add support for non-visible inclusions if required)
    -Updated Formvalidator to iterate removal of errorTips
    -Updated TourDeJewel PopUpPlayGround example to remove error tips when form popup is closed
    @todo: remove error tips from Forms and Validation example when navigating away from that to another Playground
---
 .../src/main/royale/PopUpPlayGround.mxml           |  5 +-
 .../src/main/royale/components/FormExample.mxml    | 14 ++---
 .../projects/Jewel/src/main/royale/JewelClasses.as | 14 +++--
 .../royale/jewel/beads/validators/FormValidator.as | 68 +++++++++++++++++-----
 .../royale/jewel/beads/validators/Validator.as     | 34 +++++------
 .../jewel/beads/validators/removeErrorTip.as       | 38 ++++++++++++
 6 files changed, 128 insertions(+), 45 deletions(-)

diff --git a/examples/royale/TourDeJewel/src/main/royale/PopUpPlayGround.mxml b/examples/royale/TourDeJewel/src/main/royale/PopUpPlayGround.mxml
index dbabd35..0acfe95 100644
--- a/examples/royale/TourDeJewel/src/main/royale/PopUpPlayGround.mxml
+++ b/examples/royale/TourDeJewel/src/main/royale/PopUpPlayGround.mxml
@@ -63,8 +63,9 @@ limitations under the License.
 				<!-- PopUp 2-->
 				<j:Label text="Click the button below to display a non modal PopUp"/>
 				<j:Button text="show popup: {popup2.open}" emphasis="primary" click="popup2.open = !popup2.open;"/>
-				<j:PopUp id="popup2">
-					<c:FormExample label="Form example in a PopUp" width="490" height="392"/>
+				<j:PopUp id="popup2"
+						 closePopUp="popupFormContent.formValidator.removeAllErrorTips()">
+					<c:FormExample localId="popupFormContent" label="Form example in a PopUp" width="490" height="392"/>
 				</j:PopUp>
 			</j:Card>
 		</j:GridCell>
diff --git a/examples/royale/TourDeJewel/src/main/royale/components/FormExample.mxml b/examples/royale/TourDeJewel/src/main/royale/components/FormExample.mxml
index 568bd66..ae833bc 100644
--- a/examples/royale/TourDeJewel/src/main/royale/components/FormExample.mxml
+++ b/examples/royale/TourDeJewel/src/main/royale/components/FormExample.mxml
@@ -17,10 +17,10 @@ See the License for the specific language governing permissions and
 limitations under the License.
 
 -->
-<j:Form xmlns:fx="http://ns.adobe.com/mxml/2009" 
-    xmlns:j="library://ns.apache.org/royale/jewel" 
-    xmlns:js="library://ns.apache.org/royale/basic" 
-    xmlns:html="library://ns.apache.org/royale/html" 
+<j:Form xmlns:fx="http://ns.adobe.com/mxml/2009"
+    xmlns:j="library://ns.apache.org/royale/jewel"
+    xmlns:js="library://ns.apache.org/royale/basic"
+    xmlns:html="library://ns.apache.org/royale/html"
     xmlns:models="models.*" valid="doSubmit(event)">
 
     <fx:Script>
@@ -41,7 +41,7 @@ limitations under the License.
             public function doSubmit(event:Event):void {
 				Alert.show("Data is valid submitted", "Sending Form!");
             }
-            
+
             /**
              * @royalesuppresspublicvarwarning
              */
@@ -50,7 +50,7 @@ limitations under the License.
     </fx:Script>
 
     <j:beads>
-        <j:FormValidator trigger="{btn}" triggerEvent="click" requiredFieldError="There are invalid data, please check it."/>
+        <j:FormValidator id="formValidator" trigger="{btn}" triggerEvent="click" requiredFieldError="There are invalid data, please check it."/>
         <js:ContainerDataBinding/>
     </j:beads>
 
@@ -108,4 +108,4 @@ limitations under the License.
             <j:Button localId="btn" text="send" emphasis="primary"/>
         </j:HGroup>
     </j:FormItem>
-</j:Form>
\ No newline at end of file
+</j:Form>
diff --git a/frameworks/projects/Jewel/src/main/royale/JewelClasses.as b/frameworks/projects/Jewel/src/main/royale/JewelClasses.as
index 06fbfb0..99cb5ed 100644
--- a/frameworks/projects/Jewel/src/main/royale/JewelClasses.as
+++ b/frameworks/projects/Jewel/src/main/royale/JewelClasses.as
@@ -56,7 +56,7 @@ package
 		import org.apache.royale.jewel.beads.controllers.SnackbarController; SnackbarController;
 		import org.apache.royale.jewel.beads.controllers.DropDownListController; DropDownListController;
         import org.apache.royale.jewel.beads.controllers.WizardController; WizardController;
-        
+
         import org.apache.royale.jewel.beads.views.PopUpView; PopUpView;
         import org.apache.royale.jewel.beads.views.ImageView; ImageView;
         import org.apache.royale.jewel.beads.views.SpinnerView; SpinnerView;
@@ -76,11 +76,11 @@ package
         import org.apache.royale.jewel.beads.views.FormItemView; FormItemView;
         import org.apache.royale.jewel.beads.views.FormHeadingView; FormHeadingView;
         import org.apache.royale.jewel.beads.views.WizardView; WizardView;
-        
+
         COMPILE::SWF
 	    {
             import org.apache.royale.jewel.beads.views.TextFieldView; TextFieldView;
-            
+
             import org.apache.royale.jewel.beads.views.SliderThumbView; SliderThumbView;
             import org.apache.royale.jewel.beads.views.SliderTrackView; SliderTrackView;
 
@@ -91,7 +91,7 @@ package
             // import org.apache.royale.jewel.beads.views.DropDownListView; DropDownListView;
             import org.apache.royale.jewel.beads.controllers.DropDownListController; DropDownListController;
         }
-        
+
         import org.apache.royale.jewel.supportClasses.ResponsiveSizes; ResponsiveSizes;
 
         import org.apache.royale.jewel.supportClasses.INavigationRenderer; INavigationRenderer;
@@ -107,10 +107,12 @@ package
         import org.apache.royale.jewel.supportClasses.list.DataGroup; DataGroup;
         import org.apache.royale.jewel.supportClasses.formitem.FormItemLayoutProxy; FormItemLayoutProxy;
         import org.apache.royale.jewel.supportClasses.wizard.WizardLayoutProxy; WizardLayoutProxy;
-        
+
         import org.apache.royale.jewel.supportClasses.util.positionInsideBoundingClientRect; positionInsideBoundingClientRect;
 
         //import org.apache.royale.jewel.beads.views.JewelLabelViewBead; JewelLabelViewBead;
+
+        import org.apache.royale.jewel.beads.validators.removeErrorTip; removeErrorTip;
     }
 
-}
\ No newline at end of file
+}
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 f6b3bf9..24b6f12 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
@@ -53,7 +53,7 @@ package org.apache.royale.jewel.beads.validators
 
 		/**
 		 *  Contains true if any validator in the form generated a validation failure.
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -65,8 +65,8 @@ package org.apache.royale.jewel.beads.validators
 
 		/**
 		 *  Override of the base class validate() method to call all validators in the form.
-		 *  dispatch invalid/valid event when validation fails/succeeds. 
-		 * 
+		 *  dispatch invalid/valid event when validation fails/succeeds.
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -74,30 +74,72 @@ package org.apache.royale.jewel.beads.validators
 		 */
 		override public function validate(event:Event = null):Boolean {
 			_isError = false;
-			validateAll(hostComponent as Group);
+            iterateAll(hostComponent as Group, true);
 			if (isError) {
                 if (requiredFieldError) Snackbar.show(requiredFieldError);
 				hostComponent.dispatchEvent(new Event("invalid"));
 			} else {
 				hostComponent.dispatchEvent(new Event("valid"));
 			}
-			
+
 			return !isError;
 		}
 
-		protected function validateAll(group:Group):void {
+		protected function iterateAll(group:Group, validateAction:Boolean, visibleOnly:Boolean = true):void {
 			for(var i:int=0; i < group.numElements; i++) {
 				var child:UIBase = group.getElementAt(i) as UIBase;
+				if (visibleOnly && !child.visible) continue;
 				var validator:Validator = child.getBeadByType(Validator) as Validator;
-				if (validator && !(validator is FormValidator)) {
-					if(!validator.validate()) {
-						_isError = true;
+                if (validator) {
+					if (validator == this) {
+						if (!validateAction) destroyErrorTip();
+					} else {
+                        if (validator is FormValidator) {
+                            if (validateAction) {
+                                if(!validator.validate()) {
+                                    _isError = true;
+                                }
+                            } else {
+                                FormValidator(validator).removeAllErrorTips();
+                            }
+                            continue;
+                        }
+
+                        if (validateAction) {
+                            if(!validator.validate()) {
+                                _isError = true;
+                            }
+                        } else {
+                            validator.destroyErrorTip();
+                        }
 					}
-				}
+                }
 				if (child is Group) {
-					validateAll(child as Group);
-				}	
+                    iterateAll(child as Group, validateAction, visibleOnly);
+				}
+			}
+		}
+
+        /**
+         *  Utility function to remove all error tips below an upper level which defaults
+		 *  to the host of this FormValidator bead. If an explicit group is passed as the upper
+		 *  level to iterate from, it should by convention be some child in the hierarchy below
+		 *  the host of this FormValidator bead, but that requirement is not enforced.
+		 *
+         *
+         *  @langversion 3.0
+         *  @playerversion Flash 10.2
+         *  @playerversion AIR 2.6
+         *  @productversion Royale 0.9.4
+		 *
+		 *  @royaleignorecoercion org.apache.royale.jewel.Group
+         */
+		public function removeAllErrorTips(below:Group = null, onlyVisible:Boolean = false):void{
+			if (!below) below = hostComponent as Group;
+			if (below == (hostComponent as Group)) {
+                destroyErrorTip();
 			}
+            iterateAll(below, false, onlyVisible);
 		}
 	}
-}
\ No newline at end of file
+}
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 072b53c..91e74e5 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
@@ -58,7 +58,7 @@ package org.apache.royale.jewel.beads.validators
 		public static const LEFT:int = 10002;
 		public static const RIGHT:int = 10003;
 		public static const MIDDLE:int = 10004;
-		
+
 		private var _errorTip:ErrorTipLabel;
 		private var _host:IPopUpHost;
 		private var _xPos:int = LEFT;
@@ -69,7 +69,7 @@ package org.apache.royale.jewel.beads.validators
 		private var _trigger:IEventDispatcher;
 		/**
 		 * Specifies the component generating the event that triggers the validator.
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -94,7 +94,7 @@ package org.apache.royale.jewel.beads.validators
 		private var _triggerEvent:String = Event.CHANGE;
 		/**
 		 * Specifies the event that triggers the validation.
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -123,7 +123,7 @@ package org.apache.royale.jewel.beads.validators
 		COMPILE::JS
 		protected var hostClassList:DOMTokenList;
 
-		/**                         	
+		/**
 		 *  @copy org.apache.royale.core.IBead#strand
 		 *
 		 *  @langversion 3.0
@@ -143,7 +143,7 @@ package org.apache.royale.jewel.beads.validators
 		}
 		/**
 		 *  Contains true if the field generated a validation failure.
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -159,7 +159,7 @@ package org.apache.royale.jewel.beads.validators
 		 *  validateFunction(item:Object):String
 		 *  Where item is the hostComponent object
 		 *  and return the error text, if valid return null
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -172,7 +172,7 @@ package org.apache.royale.jewel.beads.validators
 		}
 		/**
 		 *  set your custom validation logic
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -181,7 +181,7 @@ package org.apache.royale.jewel.beads.validators
 		public function set validateFunction(func:Function):void{
 			_validateFunction = func;
 		}
-		
+
 		private var _required:int;
 
 		public function get required():int {
@@ -190,7 +190,7 @@ package org.apache.royale.jewel.beads.validators
 
 		/**
 		 *  specifies that at least required quantity causes a validation error.
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -222,7 +222,7 @@ package org.apache.royale.jewel.beads.validators
 		 *  Performs validation and return the result.
 		 *  When result is false(invalid), errorTip appears on the control.
 		 *  And true(valid), the errorTip will disappear.
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -270,11 +270,11 @@ package org.apache.royale.jewel.beads.validators
 		{
 			_yPos = pos;
 		}
-		
+
 
 		/**
 		 *  Create an errorTip that floats a error text over a control
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -305,7 +305,7 @@ package org.apache.royale.jewel.beads.validators
 
 			COMPILE::JS
 			{
-				if (!hostClassList.contains("errorBorder")) 
+				if (!hostClassList.contains("errorBorder"))
 					hostClassList.add("errorBorder");
 			}
 		}
@@ -323,7 +323,7 @@ package org.apache.royale.jewel.beads.validators
 
 		/**
 		 *  Determines the position of the errorTip.
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
@@ -363,19 +363,19 @@ package org.apache.royale.jewel.beads.validators
 
         /**
          *  Destroy the created errorTip
-		 * 
+		 *
 		 *  @langversion 3.0
 		 *  @playerversion Flash 10.2
 		 *  @playerversion AIR 2.6
 		 *  @productversion Royale 0.9.4
          */
-        protected function destroyErrorTip():void
+        internal function destroyErrorTip():void
         {
             if (_errorTip) {
                 _host.popUpParent.removeElement(_errorTip);
 
 				_errorTip = null;
-				
+
 				COMPILE::JS
 				{
 					if (hostClassList.contains("errorBorder"))
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/removeErrorTip.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/removeErrorTip.as
new file mode 100644
index 0000000..4db029c
--- /dev/null
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/removeErrorTip.as
@@ -0,0 +1,38 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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
+{
+
+
+
+        /**
+         *  Destroy the created errorTip for a validator instance
+         *  import this utility function to support this functionality in externally defined subclasses.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.4
+         */
+        public function removeErrorTip(validator:Validator):void
+        {
+            validator.destroyErrorTip();
+        }
+
+}