Repository: flex-asjs
Updated Branches:
  refs/heads/develop 9f867260d -> 8fbdd3783


Refactor to “Restrict” bead to allow all kind of restrictions


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/8fbdd378
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/8fbdd378
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/8fbdd378

Branch: refs/heads/develop
Commit: 8fbdd3783702ff433e76fa9eb7fad5e8f2ef79de
Parents: 9f86726
Author: Carlos Rovira <[email protected]>
Authored: Tue Nov 29 23:18:46 2016 +0100
Committer: Carlos Rovira <[email protected]>
Committed: Tue Nov 29 23:18:46 2016 +0100

----------------------------------------------------------------------
 .../MDLExample/src/main/flex/TextFields.mxml    |   8 +-
 .../main/flex/org/apache/flex/mdl/TextField.as  |  16 ++-
 .../flex/org/apache/flex/mdl/beads/Numeric.as   | 129 -----------------
 .../flex/org/apache/flex/mdl/beads/Restrict.as  | 139 +++++++++++++++++++
 .../src/main/resources/mdl-manifest.xml         |   2 +-
 5 files changed, 159 insertions(+), 135 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fbdd378/examples/flexjs/MDLExample/src/main/flex/TextFields.mxml
----------------------------------------------------------------------
diff --git a/examples/flexjs/MDLExample/src/main/flex/TextFields.mxml 
b/examples/flexjs/MDLExample/src/main/flex/TextFields.mxml
index e5fadf6..c46e8a4 100644
--- a/examples/flexjs/MDLExample/src/main/flex/TextFields.mxml
+++ b/examples/flexjs/MDLExample/src/main/flex/TextFields.mxml
@@ -41,15 +41,15 @@ limitations under the License.
 
         <mdl:TextField>
             <js:beads>
-                <mdl:TextPrompt prompt="Number..."/>
-                <mdl:Numeric text="This is not a number."/>
+                <mdl:TextPrompt prompt="Letters and spaces..."/>
+                <mdl:Restrict pattern="[A-Z,a-z, ]*" error="Letters and spaces 
only"/>
             </js:beads>
         </mdl:TextField>
 
         <mdl:TextField floatingLabel="true">
             <js:beads>
-                <mdl:TextPrompt prompt="Number..."/>
-                <mdl:Numeric/>
+                <mdl:TextPrompt prompt="Numbers..."/>
+                <mdl:Restrict pattern="-?[0-9]*(\.[0-9]+)?" error="Input is 
not a number!"/>
             </js:beads>
         </mdl:TextField>
     

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fbdd378/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextField.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextField.as
 
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextField.as
index 499cef3..710c25b 100644
--- 
a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextField.as
+++ 
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextField.as
@@ -66,8 +66,22 @@ package org.apache.flex.mdl
             {
                 _textNode = value;
             }
+
+            private var _input:HTMLInputElement;
+
+            public function get input():HTMLInputElement
+            {
+                return _input;
+            }
+
+            public function set input(value:HTMLInputElement):void
+            {
+                _input = value;
+            }
         }
         
+
+
         /**
          * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement
          * @flexjsignorecoercion HTMLDivElement
@@ -83,7 +97,7 @@ package org.apache.flex.mdl
             var div:HTMLDivElement = document.createElement('div') as 
HTMLDivElement;
             div.className = typeNames;
 
-            var input:HTMLInputElement = document.createElement('input') as 
HTMLInputElement;
+            input = document.createElement('input') as HTMLInputElement;
             input.setAttribute('type', 'text');
             input.className = "mdl-textfield__input";
             

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fbdd378/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/Numeric.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/Numeric.as
 
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/Numeric.as
deleted file mode 100644
index 6f28433..0000000
--- 
a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/Numeric.as
+++ /dev/null
@@ -1,129 +0,0 @@
-////////////////////////////////////////////////////////////////////////////////
-//
-//  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.flex.mdl.beads
-{
-       COMPILE::SWF
-       {
-               import flash.text.TextFieldType;                        
-               
-               import org.apache.flex.core.CSSTextField;
-       }
-       
-       import org.apache.flex.core.IBead;
-       import org.apache.flex.core.IStrand;
-       import org.apache.flex.core.UIBase;
-       import org.apache.flex.events.Event;
-       import org.apache.flex.events.IEventDispatcher;
-
-    import org.apache.flex.mdl.TextField;
-       
-       /**
-        *  The TextPrompt class is a specialty bead that can be used with
-        *  any TextField control. The bead places a string into the input field
-        *  when there is no value associated with the text property.
-        *  
-        *  @langversion 3.0
-        *  @playerversion Flash 10.2
-        *  @playerversion AIR 2.6
-        *  @productversion FlexJS 0.0
-        */
-       public class Numeric implements IBead
-       {
-               /**
-                *  constructor.
-                *
-                *  @langversion 3.0
-                *  @playerversion Flash 10.2
-                *  @playerversion AIR 2.6
-                *  @productversion FlexJS 0.0
-                */
-               public function Numeric()
-               {
-               }
-               
-               private var _pattern:String = "-?[0-9]*(\.[0-9]+)?";
-               
-               /**
-                *  The string to use as numeric pattern.
-                *
-                *  @langversion 3.0
-                *  @playerversion Flash 10.2
-                *  @playerversion AIR 2.6
-                *  @productversion FlexJS 0.0
-                */
-               public function get pattern():String
-               {
-                       return _pattern;
-               }
-               public function set pattern(value:String):void
-               {
-                       _pattern = value;
-               }
-               
-        private var _text:String = "Input is not a number!";
-
-        /**
-                *  The string to use as error text in the associated span.
-                *
-                *  @langversion 3.0
-                *  @playerversion Flash 10.2
-                *  @playerversion AIR 2.6
-                *  @productversion FlexJS 0.0
-                */
-        public function get text():String
-        {
-            return _text;
-        }
-        public function set text(value:String):void
-        {
-            _text = value;
-        }
-
-               private var _strand:IStrand;
-               
-               /**
-                *  @copy org.apache.flex.core.IBead#strand
-                *  
-                *  @langversion 3.0
-                *  @playerversion Flash 10.2
-                *  @playerversion AIR 2.6
-                *  @productversion FlexJS 0.0
-                *  @flexjsignorecoercion HTMLInputElement
-                *  @flexjsignorecoercion org.apache.flex.core.UIBase;
-                */
-               public function set strand(value:IStrand):void
-               {
-                       _strand = value;
-                       
-                       COMPILE::JS
-                       {
-                               var mdlTi:TextField = value as TextField;
-                mdlTi.input.setAttribute('pattern', pattern);
-
-                var span:HTMLSpanElement = document.createElement('span') as 
HTMLSpanElement;
-                span.className = "mdl-textfield__error";
-
-                var spanTextNode:Text = document.createTextNode(text) as Text;
-                span.appendChild(spanTextNode);
-
-                mdlTi.positioner.appendChild(span);
-                       }
-               }
-       }
-}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fbdd378/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/Restrict.as
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/Restrict.as
 
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/Restrict.as
new file mode 100644
index 0000000..30accdb
--- /dev/null
+++ 
b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/beads/Restrict.as
@@ -0,0 +1,139 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  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.flex.mdl.beads
+{
+       COMPILE::SWF
+       {
+               import flash.text.TextFieldType;                        
+               
+               import org.apache.flex.core.CSSTextField;
+       }
+       
+       import org.apache.flex.core.IBead;
+       import org.apache.flex.core.IStrand;
+       import org.apache.flex.core.UIBase;
+       import org.apache.flex.events.Event;
+       import org.apache.flex.events.IEventDispatcher;
+
+    import org.apache.flex.mdl.TextField;
+       
+       /**
+        *  The Restrict bead class is a specialty bead that can be used with
+        *  any TextField 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 FlexJS 0.0
+        */
+       public class Restrict implements IBead
+       {
+               /**
+                *  constructor.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+               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 FlexJS 0.0
+                */
+               public function get pattern():String
+               {
+                       return _pattern;
+               }
+               public function set pattern(value:String):void
+               {
+                       _pattern = value;
+               }
+               
+        private var _error:String = "";
+
+        /**
+                *  The string to use as error text in the associated span.
+                *
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                */
+        public function get error():String
+        {
+            return _error;
+        }
+        public function set error(value:String):void
+        {
+            _error = value;
+        }
+
+               private var _strand:IStrand;
+               
+               /**
+                *  @copy org.apache.flex.core.IBead#strand
+                *  
+                *  @langversion 3.0
+                *  @playerversion Flash 10.2
+                *  @playerversion AIR 2.6
+                *  @productversion FlexJS 0.0
+                *  @flexjsignorecoercion HTMLInputElement
+                *  @flexjsignorecoercion org.apache.flex.core.UIBase;
+                */
+               public function set strand(value:IStrand):void
+               {
+                       _strand = value;
+                       
+                       COMPILE::JS
+                       {
+                               var mdlTi:TextField = value as TextField;
+                mdlTi.input.setAttribute('pattern', pattern);
+
+                var span:HTMLSpanElement = document.createElement('span') as 
HTMLSpanElement;
+                span.className = "mdl-textfield__error";
+
+                var spanTextNode:Text = document.createTextNode(error) as Text;
+                span.appendChild(spanTextNode);
+
+                mdlTi.positioner.appendChild(span);
+                       }
+               }
+       }
+}

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/8fbdd378/frameworks/projects/MaterialDesignLite/src/main/resources/mdl-manifest.xml
----------------------------------------------------------------------
diff --git 
a/frameworks/projects/MaterialDesignLite/src/main/resources/mdl-manifest.xml 
b/frameworks/projects/MaterialDesignLite/src/main/resources/mdl-manifest.xml
index f552067..375a723 100644
--- a/frameworks/projects/MaterialDesignLite/src/main/resources/mdl-manifest.xml
+++ b/frameworks/projects/MaterialDesignLite/src/main/resources/mdl-manifest.xml
@@ -27,7 +27,7 @@
     <component id="RadioButton" class="org.apache.flex.mdl.RadioButton"/>
     <component id="Switch" class="org.apache.flex.mdl.Switch"/>
     <component id="TextPrompt" class="org.apache.flex.mdl.beads.TextPrompt"/>
-    <component id="Numeric" class="org.apache.flex.mdl.beads.Numeric"/>
+    <component id="Restrict" class="org.apache.flex.mdl.beads.Restrict"/>
     <component id="Disabled" class="org.apache.flex.mdl.beads.Disabled"/>
     <component id="Slider" class="org.apache.flex.mdl.Slider"/>
     <component id="Badge" class="org.apache.flex.mdl.beads.Badge"/>

Reply via email to