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

aharui 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 315ec74  handle paste restrict.  Fixed #662
315ec74 is described below

commit 315ec7469a6929479ea2f6ce98f19602470ea714
Author: Alex Harui <[email protected]>
AuthorDate: Wed Jan 8 14:20:24 2020 -0800

    handle paste restrict.  Fixed #662
---
 .../html/accessories/RestrictTextInputBead.as      | 38 ++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/RestrictTextInputBead.as
 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/RestrictTextInputBead.as
index 72db29d..bf89eb4 100644
--- 
a/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/RestrictTextInputBead.as
+++ 
b/frameworks/projects/Basic/src/main/royale/org/apache/royale/html/accessories/RestrictTextInputBead.as
@@ -85,7 +85,8 @@ package org.apache.royale.html.accessories
                        COMPILE::JS
                        {
                 var host:UIBase = _strand as UIBase;
-                host.element.addEventListener("keypress", validateInput, 
false);
+                host.element.addEventListener("keypress", validateKeypress, 
false);
+                host.element.addEventListener("input", validateInput, false);
                        }
                }
                
@@ -129,7 +130,7 @@ package org.apache.royale.html.accessories
                }
                                
                COMPILE::JS
-               private function validateInput(event:BrowserEvent):void
+               private function validateKeypress(event:BrowserEvent):void
                {
                        var code:int = event.charCode;
                        
@@ -145,5 +146,38 @@ package org.apache.royale.html.accessories
                        }
             }
                }
+        
+        /**
+         *  @royaleignorecoercion HTMLInputElement 
+         */
+        COMPILE::JS
+        private function validateInput(event:BrowserEvent):void
+        {            
+            var data:String = event["data"];
+            
+            if (restrict && data != null && data.length > 0)
+            {
+                var regex:RegExp = new RegExp("[" + restrict + "]");
+                var out:String = "";
+                var n:int = data.length;
+                var blocked:Boolean = false;
+                for (var i:int = 0; i < n; i++)
+                {
+                    var key:String = data.charAt(i);
+                    if (regex.test(key)) {
+                        out += key;
+                    }
+                    else
+                        blocked = true;
+                }
+                if (blocked) 
+                {
+                    event["returnValue"] = false;
+                    if (event.preventDefault) event.preventDefault();
+                    var host:UIBase = _strand as UIBase;
+                    (host.element as HTMLInputElement).value = out;            
        
+                }
+            }
+        }
        }
 }

Reply via email to