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

yishayw 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 cadcdb2514 Add RestrictToColorTextInputBead and use in emulation CP
cadcdb2514 is described below

commit cadcdb25141cddc3bda548886a723e4dd225be56
Author: Yishay Weiss <[email protected]>
AuthorDate: Thu Dec 1 18:09:23 2022 +0200

    Add RestrictToColorTextInputBead and use in emulation CP
---
 .../projects/Basic/src/main/royale/BasicClasses.as |   1 +
 .../accessories/RestrictToColorTextInputBead.as    | 101 +++++++++++++++++++++
 .../royale/mx/controls/beads/ColorPickerPopUp.as   |   5 +-
 3 files changed, 104 insertions(+), 3 deletions(-)

diff --git a/frameworks/projects/Basic/src/main/royale/BasicClasses.as 
b/frameworks/projects/Basic/src/main/royale/BasicClasses.as
index fab74b8242..f5591dcad6 100644
--- a/frameworks/projects/Basic/src/main/royale/BasicClasses.as
+++ b/frameworks/projects/Basic/src/main/royale/BasicClasses.as
@@ -37,6 +37,7 @@ internal class BasicClasses
        import org.apache.royale.html.ToolTip; ToolTip;
        import org.apache.royale.html.accessories.NumericOnlyTextInputBead; 
NumericOnlyTextInputBead;
        import org.apache.royale.html.accessories.RestrictTextInputBead; 
RestrictTextInputBead;
+       import org.apache.royale.html.accessories.RestrictToColorTextInputBead; 
RestrictToColorTextInputBead;
        import org.apache.royale.html.accessories.PasswordInputBead; 
PasswordInputBead;
        import org.apache.royale.html.accessories.PasswordInputRemovableBead; 
PasswordInputRemovableBead;
        import org.apache.royale.html.accessories.TextPromptBead; 
TextPromptBead;
diff --git 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/RestrictToColorTextInputBead.as
 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/RestrictToColorTextInputBead.as
new file mode 100644
index 0000000000..fd45823841
--- /dev/null
+++ 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/RestrictToColorTextInputBead.as
@@ -0,0 +1,101 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.html.accessories
+{
+       COMPILE::JS
+       {
+               import goog.events.BrowserEvent;
+       }
+       import org.apache.royale.core.IBead;
+       import org.apache.royale.core.IStrand;
+       import org.apache.royale.core.Bead;
+       import org.apache.royale.core.IRenderedObject;
+       
+       /**
+        *  The RestrictToColorTextInputBead class is a specialty bead that can 
be used with
+        *  any TextInput control. The bead prevents characters that will not 
yield a hexa color from being 
+        *  entered into the text input area.
+        *  
+        *  @langversion 3.0
+        *  @playerversion Flash 10.2
+        *  @playerversion AIR 2.6
+        *  @productversion Royale 0.9.10
+        */
+       public class RestrictToColorTextInputBead extends Bead
+       {
+               private var _validValue:String = "";
+               /**
+                *  constructor.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.10
+                */
+               public function RestrictToColorTextInputBead()
+               {
+               }
+               
+               /**
+                *  @copy org.apache.royale.core.IBead#strand
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion Royale 0.9.10
+                *  @royaleignorecoercion org.apache.royale.core.IRenderedObject
+                */
+               override public function set strand(value:IStrand):void
+               {
+                       _strand = value;
+                       
+                       COMPILE::JS
+                       {
+                               var host:IRenderedObject = _strand as 
IRenderedObject;
+                               host.element.addEventListener("input", 
validateInput, false);
+                       }
+               }
+               
+        
+               /**
+                *  @royaleignorecoercion HTMLInputElement 
+                *  @royaleignorecoercion org.apache.royale.core.IRenderedObject
+                */
+               COMPILE::JS
+               private function validateInput(event:BrowserEvent):void
+               {            
+                       var host:IRenderedObject = _strand as IRenderedObject;
+                       var data:String = (host.element as 
HTMLInputElement).value;
+                       
+                       if (data != null)
+                       {
+                               var regex:RegExp = new 
RegExp("^[0-9a-fA-F]{0,6}$");
+                               if (regex.test(data)) 
+                               {
+                                       _validValue = data;
+                               } else
+                               {
+                                       event["returnValue"] = false;
+                                       if (event.preventDefault) 
event.preventDefault();
+                                       (host.element as 
HTMLInputElement).value = _validValue;                    
+                               }
+                       }
+               }
+       }
+}
diff --git 
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/ColorPickerPopUp.as
 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/ColorPickerPopUp.as
index 3dbc08b0e6..f4773b6575 100644
--- 
a/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/ColorPickerPopUp.as
+++ 
b/frameworks/projects/MXRoyale/src/main/royale/mx/controls/beads/ColorPickerPopUp.as
@@ -33,7 +33,7 @@ package mx.controls.beads
        import org.apache.royale.events.Event;
        import org.apache.royale.utils.CSSUtils;
        import org.apache.royale.html.beads.DispatchInputFinishedBead;
-       import org.apache.royale.html.accessories.RestrictTextInputBead;
+       import org.apache.royale.html.accessories.RestrictToColorTextInputBead;
        import org.apache.royale.core.IStrandWithModel;
 
        /**
@@ -108,8 +108,7 @@ package mx.controls.beads
                {
                        host = value;
                        textInput.addEventListener("change", changeHandler);
-                       var restrictBead:RestrictTextInputBead = new 
RestrictTextInputBead();
-                       restrictBead.restrict = "aAbBcCdDeEfF0123456789";
+                       var restrictBead:RestrictToColorTextInputBead = new 
RestrictToColorTextInputBead();
                        textInput.addBead(restrictBead);
                        textInput.addBead(new DispatchInputFinishedBead());
                        
textInput.addEventListener(DispatchInputFinishedBead.INPUT_FINISHED, 
inputFinishedHandler)

Reply via email to