You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2020/01/08 22:20:43 UTC
[royale-asjs] branch develop updated: handle paste restrict. Fixed
#662
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 <ah...@apache.org>
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;
+ }
+ }
+ }
}
}