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

piotrz 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 79b01b64bb Jewel: Add RestrictValidator - validate based on 
StringValidator capabilities and RegExp pattern
79b01b64bb is described below

commit 79b01b64bba09cd51265de0e2c073904f4eb9a19
Author: Piotr Zarzycki <[email protected]>
AuthorDate: Mon Jul 1 18:54:21 2024 +0200

    Jewel: Add RestrictValidator - validate based on StringValidator 
capabilities and RegExp pattern
    
    - Add new classes to jewel-manifest
---
 .../Jewel/src/main/resources/jewel-manifest.xml    |   2 +
 .../jewel/beads/validators/RestrictValidator.as    | 111 +++++++++++++++++++++
 2 files changed, 113 insertions(+)

diff --git a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml 
b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
index 89d4064c02..558e5ed1f5 100644
--- a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
+++ b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
@@ -115,6 +115,7 @@
     <component id="FormValidator" 
class="org.apache.royale.jewel.beads.validators.FormValidator"/>
     <component id="FormValidatorWithoutSnackbar" 
class="org.apache.royale.jewel.beads.validators.FormValidatorWithoutSnackbar"/>
     <component id="StringValidator" 
class="org.apache.royale.jewel.beads.validators.StringValidator"/>
+    <component id="RestrictValidator" 
class="org.apache.royale.jewel.beads.validators.RestrictValidator"/>
     <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"/>
@@ -221,6 +222,7 @@
     <component id="PasswordInput" 
class="org.apache.royale.jewel.beads.controls.textinput.PasswordInput"/>
     <component id="MaxNumberCharacters" 
class="org.apache.royale.jewel.beads.controls.textinput.MaxNumberCharacters"/>
     <component id="Restrict" 
class="org.apache.royale.jewel.beads.controls.textinput.Restrict"/>
+    <component id="RestrictRegExp" 
class="org.apache.royale.jewel.beads.controls.textinput.RestrictRegExp"/>
     <component id="UpperCase" 
class="org.apache.royale.jewel.beads.controls.textinput.UpperCase"/>
     <component id="AutoScroll" 
class="org.apache.royale.jewel.beads.controls.textinput.AutoScroll"/>
     <component id="SearchFilterForList" 
class="org.apache.royale.jewel.beads.controls.textinput.SearchFilterForList"/>
diff --git 
a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/RestrictValidator.as
 
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/RestrictValidator.as
new file mode 100644
index 0000000000..6abd884a88
--- /dev/null
+++ 
b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/validators/RestrictValidator.as
@@ -0,0 +1,111 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.IBead;
+       import org.apache.royale.core.IStrand;
+       import org.apache.royale.events.Event;
+    import org.apache.royale.jewel.supportClasses.textinput.TextInputBase;
+
+       /**
+        *  The RestrictValidator class is a specialty bead that can be used 
with
+        *  TextInput control.
+        *
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.11
+        */
+       public class RestrictValidator extends StringValidator
+       {
+               /**
+                *  constructor.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.11
+                */
+               public function RestrictValidator()
+               {
+                       super();
+               }
+
+        private var _pattern:RegExp;
+
+               /**
+                *  The RegExp to validate TextInput.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.11
+                */
+               public function get pattern():RegExp
+               {
+                       return _pattern;
+               }
+
+               public function set pattern(value:RegExp):void
+               {
+                   if (_pattern != value)
+                   {
+                           _pattern = value;
+                       }
+               }
+
+               /**                             
+                *  @copy org.apache.royale.core.IBead#strand
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.11
+                *  @royaleignorecoercion 
org.apache.royale.events.IEventDispatcher
+                */
+               override public function set strand(value:IStrand):void
+               {
+                       super.strand = value;
+               }
+
+               /**
+                *  Override of the base class validate() method to validate a 
String.
+                * 
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.11
+                */
+               override public function validate(event:Event = null):Boolean {
+                       if (super.validate(event))
+                       {
+                           var txt:TextInputBase = hostComponent as 
TextInputBase;
+                           if (pattern && pattern.test(txt.text))
+                           {
+                               createErrorTip(requiredFieldError);
+                           }
+                           else
+                           {
+                               destroyErrorTip();
+                           }
+                       }
+                       return !isError;
+               }
+       }
+}

Reply via email to