Refactor to TextFieldBase to remove duplicated code and better management of common functionality
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/81bf74d4 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/81bf74d4 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/81bf74d4 Branch: refs/heads/feature/fontawesome Commit: 81bf74d4cece0220d845ab782cef5bbe31f34c17 Parents: 3724857 Author: Carlos Rovira <[email protected]> Authored: Sun Jan 1 20:08:46 2017 +0100 Committer: Carlos Rovira <[email protected]> Committed: Sun Jan 1 20:08:46 2017 +0100 ---------------------------------------------------------------------- .../MDLExample/src/main/flex/TextFields.mxml | 5 +- .../main/flex/org/apache/flex/mdl/TextArea.as | 87 +--------- .../main/flex/org/apache/flex/mdl/TextField.as | 87 +--------- .../flex/mdl/supportClasses/TextFieldBase.as | 162 +++++++++++++++++++ 4 files changed, 168 insertions(+), 173 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/81bf74d4/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 a448b9a..8c50fc2 100644 --- a/examples/flexjs/MDLExample/src/main/flex/TextFields.mxml +++ b/examples/flexjs/MDLExample/src/main/flex/TextFields.mxml @@ -81,10 +81,9 @@ limitations under the License. </mdl:beads> </mdl:TextArea> - <mdl:TextArea floatingLabel="true" width="100%" rows="5" maxrows="8"> + <mdl:TextArea floatingLabel="true" width="100%" rows="5" maxrows="8" isInvalid="true"> <mdl:beads> - <mdl:TextPrompt prompt="Floating, maxrows 8 and only letters..."/> - <mdl:Restrict pattern="[A-Z,a-z, ]*" error="Letters and spaces only"/> + <mdl:TextPrompt prompt="Floating, maxrows 8, invalid on load"/> </mdl:beads> </mdl:TextArea> </js:Form> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/81bf74d4/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextArea.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextArea.as b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextArea.as index 167485f..056e7ee 100644 --- a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextArea.as +++ b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/TextArea.as @@ -18,9 +18,8 @@ package org.apache.flex.mdl { import org.apache.flex.events.Event; - import org.apache.flex.html.TextInput; - import org.apache.flex.mdl.supportClasses.ITextField; + import org.apache.flex.mdl.supportClasses.TextFieldBase; COMPILE::JS { @@ -37,7 +36,7 @@ package org.apache.flex.mdl * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class TextArea extends org.apache.flex.html.TextInput implements ITextField + public class TextArea extends TextFieldBase { /** * Constructor. @@ -100,45 +99,6 @@ package org.apache.flex.mdl } } - COMPILE::JS - { - private var _textNode:Text; - - public function get textNode():Text - { - return _textNode; - } - - public function set textNode(value:Text):void - { - _textNode = value; - } - - private var _input:HTMLInputElement; - - public function get input():HTMLInputElement - { - return _input; - } - - public function set input(value:HTMLInputElement):void - { - _input = value; - } - - private var _label:HTMLLabelElement; - - public function get label():HTMLLabelElement - { - return _label; - } - - public function set label(value:HTMLLabelElement):void - { - _label = value; - } - } - /** * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement * @flexjsignorecoercion HTMLDivElement @@ -182,48 +142,5 @@ package org.apache.flex.mdl return element; } - - private var _className:String; - - /** - * since we have a div surronding the main input, we need to - * route the class assignaments to div - */ - override public function set className(value:String):void - { - if (_className != value) - { - COMPILE::JS - { - positioner.className = typeNames ? value + ' ' + typeNames : value; - } - _className = value; - dispatchEvent(new Event("classNameChanged")); - } - } - - private var _floatingLabel:Boolean = false; - /** - * A boolean flag to activate "mdl-textfield--floating-label" effect selector. - * Applies floating label effect. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get floatingLabel():Boolean - { - return _floatingLabel; - } - public function set floatingLabel(value:Boolean):void - { - _floatingLabel = value; - - COMPILE::JS - { - positioner.classList.toggle("mdl-textfield--floating-label", _floatingLabel); - } - } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/81bf74d4/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 dba1384..f68a02a 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 @@ -18,9 +18,8 @@ package org.apache.flex.mdl { import org.apache.flex.events.Event; - import org.apache.flex.html.TextInput; - import org.apache.flex.mdl.supportClasses.ITextField; + import org.apache.flex.mdl.supportClasses.TextFieldBase; COMPILE::JS { @@ -37,7 +36,7 @@ package org.apache.flex.mdl * @playerversion AIR 2.6 * @productversion FlexJS 0.0 */ - public class TextField extends org.apache.flex.html.TextInput implements ITextField + public class TextField extends TextFieldBase { /** * Constructor. @@ -53,45 +52,6 @@ package org.apache.flex.mdl className = ""; //set to empty string avoid 'undefined' output when no class selector is assigned by user; } - - COMPILE::JS - { - private var _textNode:Text; - - public function get textNode():Text - { - return _textNode; - } - - public function set textNode(value:Text):void - { - _textNode = value; - } - - private var _input:HTMLInputElement; - - public function get input():HTMLInputElement - { - return _input; - } - - public function set input(value:HTMLInputElement):void - { - _input = value; - } - - private var _label:HTMLLabelElement; - - public function get label():HTMLLabelElement - { - return _label; - } - - public function set label(value:HTMLLabelElement):void - { - _label = value; - } - } /** * @flexjsignorecoercion org.apache.flex.core.WrappedHTMLElement @@ -134,48 +94,5 @@ package org.apache.flex.mdl return element; } - - private var _className:String; - - /** - * since we have a div surronding the main input, we need to - * route the class assignaments to div - */ - override public function set className(value:String):void - { - if (_className != value) - { - COMPILE::JS - { - positioner.className = typeNames ? value + ' ' + typeNames : value; - } - _className = value; - dispatchEvent(new Event("classNameChanged")); - } - } - - private var _floatingLabel:Boolean = false; - /** - * A boolean flag to activate "mdl-textfield--floating-label" effect selector. - * Applies floating label effect. - * - * @langversion 3.0 - * @playerversion Flash 10.2 - * @playerversion AIR 2.6 - * @productversion FlexJS 0.0 - */ - public function get floatingLabel():Boolean - { - return _floatingLabel; - } - public function set floatingLabel(value:Boolean):void - { - _floatingLabel = value; - - COMPILE::JS - { - positioner.classList.toggle("mdl-textfield--floating-label", _floatingLabel); - } - } } } http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/81bf74d4/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/supportClasses/TextFieldBase.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/supportClasses/TextFieldBase.as b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/supportClasses/TextFieldBase.as new file mode 100644 index 0000000..748ee46 --- /dev/null +++ b/frameworks/projects/MaterialDesignLite/src/main/flex/org/apache/flex/mdl/supportClasses/TextFieldBase.as @@ -0,0 +1,162 @@ +// +// 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.supportClasses +{ + import org.apache.flex.events.Event; + import org.apache.flex.html.TextInput; + + import org.apache.flex.mdl.supportClasses.ITextField; + + COMPILE::JS + { + import goog.events; + import org.apache.flex.core.WrappedHTMLElement; + } + + /** + * The TextFieldBase class is the base class for TextField and TextArea MDL controls + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class TextFieldBase extends org.apache.flex.html.TextInput implements ITextField + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function TextFieldBase() + { + super(); + + className = ""; //set to empty string avoid 'undefined' output when no class selector is assigned by user; + } + + COMPILE::JS + { + private var _textNode:Text; + + public function get textNode():Text + { + return _textNode; + } + + public function set textNode(value:Text):void + { + _textNode = value; + } + + private var _input:HTMLInputElement; + + public function get input():HTMLInputElement + { + return _input; + } + + public function set input(value:HTMLInputElement):void + { + _input = value; + } + + private var _label:HTMLLabelElement; + + public function get label():HTMLLabelElement + { + return _label; + } + + public function set label(value:HTMLLabelElement):void + { + _label = value; + } + } + + private var _className:String; + + /** + * since we have a div surronding the main input, we need to + * route the class assignaments to div + */ + override public function set className(value:String):void + { + if (_className != value) + { + COMPILE::JS + { + positioner.className = typeNames ? value + ' ' + typeNames : value; + } + _className = value; + dispatchEvent(new Event("classNameChanged")); + } + } + + private var _floatingLabel:Boolean = false; + /** + * A boolean flag to activate "mdl-textfield--floating-label" effect selector. + * Applies floating label effect. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get floatingLabel():Boolean + { + return _floatingLabel; + } + public function set floatingLabel(value:Boolean):void + { + _floatingLabel = value; + + COMPILE::JS + { + positioner.classList.toggle("mdl-textfield--floating-label", _floatingLabel); + } + } + + private var _isInvalid:Boolean = false; + /** + * A boolean flag to activate "is-invalid" effect selector. + * Defines the textfield as invalid on initial load.Optional + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get isInvalid():Boolean + { + return _isInvalid; + } + public function set isInvalid(value:Boolean):void + { + _isInvalid = value; + + COMPILE::JS + { + positioner.classList.toggle("is-invalid", _isInvalid); + } + } + } +}
