royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From carlosrov...@apache.org
Subject [royale-asjs] branch develop updated: Jewel SelectedItemNullValidator and example
Date Mon, 29 Oct 2018 17:09:21 GMT
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 513a54e  Jewel SelectedItemNullValidator and example
513a54e is described below

commit 513a54ead0abd75a08d6f39da6275df08712ee34
Author: Carlos Rovira <carlosrovira@apache.org>
AuthorDate: Mon Oct 29 18:09:13 2018 +0100

    Jewel SelectedItemNullValidator and example
---
 .../src/main/royale/FormsValidationPlayGround.mxml | 24 ++++--
 .../Jewel/src/main/resources/jewel-manifest.xml    |  1 +
 .../beads/validators/SelectedItemNullValidator.as  | 85 ++++++++++++++++++++++
 3 files changed, 104 insertions(+), 6 deletions(-)

diff --git a/examples/royale/JewelExample/src/main/royale/FormsValidationPlayGround.mxml b/examples/royale/JewelExample/src/main/royale/FormsValidationPlayGround.mxml
index feb92d1..7e11af9 100644
--- a/examples/royale/JewelExample/src/main/royale/FormsValidationPlayGround.mxml
+++ b/examples/royale/JewelExample/src/main/royale/FormsValidationPlayGround.mxml
@@ -20,12 +20,9 @@ limitations under the License.
 <j:SectionContent 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:beads>
-        <js:ContainerDataBinding/>
-    </j:beads>
-
+				  xmlns:html="library://ns.apache.org/royale/html"
+				  xmlns:models="models.*">
+				  
 	<fx:Script>
 		<![CDATA[
 			import org.apache.royale.utils.StringPadder;
@@ -44,6 +41,14 @@ limitations under the License.
 		]]>
 	</fx:Script>
 
+	<j:beads>
+        <js:ContainerDataBinding/>
+    </j:beads>
+
+	<j:model>
+        <models:ListsModel id="listModel"/>
+	</j:model>
+
 	<j:Card width="600">
 		<html:H3 text="Jewel Form And Validators"/>
 
@@ -67,6 +72,13 @@ limitations under the License.
 				</j:beads>
 			</j:DateField>
 
+			<html:H4 text="Your Favorite Avenger"/>
+			<j:ComboBox labelField="label" dataProvider="{listModel.avengers}">
+				<j:beads>
+					<j:SelectedItemNullValidator requiredFieldError="You must to select one value from
the list"/>
+				</j:beads>
+			</j:ComboBox>
+
 			<html:H4 text="Favorite movies (at least 2)"/>
 			<j:VGroup gap="3">
 				<j:beads>
diff --git a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
index 5f61221..7546e45 100644
--- a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
+++ b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
@@ -75,6 +75,7 @@
     <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="SelectedItemNullValidator" class="org.apache.royale.jewel.beads.validators.SelectedItemNullValidator"/>
     <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/SelectedItemNullValidator.as
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/SelectedItemNullValidator.as
new file mode 100644
index 0000000..374d72a
--- /dev/null
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/SelectedItemNullValidator.as
@@ -0,0 +1,85 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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 SelectedItemNullValidator class is a specialty bead that can be used with
+	 *  Group control to validate if a component (normaly list based) has a selectedItem
+	 *  with null value
+	 *
+	 *  @langversion 3.0
+	 *  @playerversion Flash 10.2
+	 *  @playerversion AIR 2.6
+	 *  @productversion Royale 0.9.4
+	 */
+	public class SelectedItemNullValidator extends Validator
+	{
+		/**
+		 *  constructor.
+		 *
+		 *  @langversion 3.0
+		 *  @playerversion Flash 10.2
+		 *  @playerversion AIR 2.6
+		 *  @productversion Royale 0.9.4
+		 */
+		public function SelectedItemNullValidator()
+		{
+			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);
+		}
+
+        /**
+		 *  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))
+            {
+				if (hostComponent["selectedItem"] == null) {
+					createErrorTip(requiredFieldError);
+				} else {
+					destroyErrorTip();
+				}	
+			}
+			return !isError;
+		}
+    }
+}


Mime
View raw message