You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2018/10/29 23:43:03 UTC
[royale-asjs] branch develop updated: Jewel Restrict bead and
examples
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 c4bc1e2 Jewel Restrict bead and examples
c4bc1e2 is described below
commit c4bc1e226f91e016881d5609e288d4f182705dc1
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Tue Oct 30 00:42:55 2018 +0100
Jewel Restrict bead and examples
---
.../src/main/royale/TextInputPlayGround.mxml | 12 ++
.../Jewel/src/main/resources/jewel-manifest.xml | 1 +
.../jewel/beads/controls/textinput/Restrict.as | 136 +++++++++++++++++++++
3 files changed, 149 insertions(+)
diff --git a/examples/royale/JewelExample/src/main/royale/TextInputPlayGround.mxml b/examples/royale/JewelExample/src/main/royale/TextInputPlayGround.mxml
index 2038f24..6d46f90 100644
--- a/examples/royale/JewelExample/src/main/royale/TextInputPlayGround.mxml
+++ b/examples/royale/JewelExample/src/main/royale/TextInputPlayGround.mxml
@@ -107,6 +107,18 @@ limitations under the License.
<j:LowerCase/>
</js:beads>
</j:TextInput>
+ <j:TextInput>
+ <js:beads>
+ <j:TextPrompt prompt="Only characters"/>
+ <j:Restrict pattern="[^a-zA-Z]"/>
+ </js:beads>
+ </j:TextInput>
+ <j:TextInput>
+ <js:beads>
+ <j:TextPrompt prompt="Only Numbers"/>
+ <j:Restrict pattern="[^0-9]"/>
+ </js:beads>
+ </j:TextInput>
</j:VGroup>
</j:Card>
</j:GridCell>
diff --git a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
index 7546e45..d2189c5 100644
--- a/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
+++ b/frameworks/projects/Jewel/src/main/resources/jewel-manifest.xml
@@ -122,6 +122,7 @@
<component id="TextPrompt" class="org.apache.royale.jewel.beads.controls.textinput.TextPrompt"/>
<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="UpperCase" class="org.apache.royale.jewel.beads.controls.textinput.UpperCase"/>
<component id="LowerCase" class="org.apache.royale.jewel.beads.controls.textinput.LowerCase"/>
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/textinput/Restrict.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/textinput/Restrict.as
new file mode 100644
index 0000000..160e6f4
--- /dev/null
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/textinput/Restrict.as
@@ -0,0 +1,136 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.controls.textinput
+{
+ COMPILE::JS
+ {
+ import goog.events.BrowserEvent;
+ }
+ COMPILE::SWF
+ {
+ import flash.events.TextEvent;
+
+ import org.apache.royale.core.CSSTextField;
+ import org.apache.royale.html.beads.ITextFieldView;
+ }
+ import org.apache.royale.core.IBead;
+ import org.apache.royale.core.IStrand;
+ import org.apache.royale.events.Event;
+ import org.apache.royale.events.IEventDispatcher;
+ import org.apache.royale.jewel.supportClasses.textinput.TextInputBase;
+ import org.apache.royale.core.UIBase;
+
+ /**
+ * The Restrict bead class is a specialty bead that can be used with
+ * any Jewel TextInputBase control. The bead uses a reg exp pattern to validate
+ * input from user. A text property allows to configure error text.
+ *
+ * use examples:
+ * Numeric pattern = -?[0-9]*(\.[0-9]+)?
+ * error text = "Input is not a number!"
+ *
+ * Letters and spaces only pattern = [A-Z,a-z, ]*
+ * error text = "Letters and spaces only";
+ *
+ * Digits only = [0-9]*
+ * error text = "Digits only";
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.4
+ */
+ public class Restrict implements IBead
+ {
+ /**
+ * constructor.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.4
+ */
+ public function Restrict()
+ {
+ }
+
+ private var _pattern:String;
+
+ /**
+ * The string to use as numeric pattern.
+ *
+ * @langversion 3.0
+ * @playerversion Flash 10.2
+ * @playerversion AIR 2.6
+ * @productversion Royale 0.9.4
+ */
+ public function get pattern():String
+ {
+ return _pattern;
+ }
+ public function set pattern(value:String):void
+ {
+ _pattern = value;
+ // updateRestriction();
+ }
+
+ private var host:TextInputBase;
+
+ // private function updateRestriction():void
+ // {
+ // COMPILE::JS
+ // {
+ // if (host)
+ // {
+ // host.input.setAttribute('pattern', pattern);
+ // }
+ // }
+ // }
+
+ /**
+ * @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.core.UIBase
+ */
+ public function set strand(value:IStrand):void
+ {
+ host = value as TextInputBase;
+ COMPILE::JS
+ {
+ host.input.addEventListener('input', keyEventHandler);
+ }
+ // updateRestriction();
+ }
+
+ /**
+ * @private
+ */
+ COMPILE::JS
+ protected function keyEventHandler(event:KeyboardEvent):void
+ {
+ //event.stopImmediatePropagation();
+ var re:RegExp = new RegExp(pattern, 'g');
+ host.input.value = host.input.value.replace(re, '');
+ }
+ }
+}