You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by pe...@apache.org on 2013/08/27 16:49:21 UTC
git commit: [flex-asjs] [refs/heads/develop] - Created package,
accessories,
for additional beads. Added NumericOnlyTextInputBead as a new accessory.
Updated Branches:
refs/heads/develop 2cb1c1e57 -> 54fb8d261
Created package, accessories, for additional beads. Added NumericOnlyTextInputBead as a new accessory.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/54fb8d26
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/54fb8d26
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/54fb8d26
Branch: refs/heads/develop
Commit: 54fb8d261009959596298b0ed349711a5b13920c
Parents: 2cb1c1e
Author: Peter Ent <pe...@apache.org>
Authored: Tue Aug 27 10:49:11 2013 -0400
Committer: Peter Ent <pe...@apache.org>
Committed: Tue Aug 27 10:49:11 2013 -0400
----------------------------------------------------------------------
frameworks/as/basic-manifest.xml | 3 +-
frameworks/as/src/FlexJSUIClasses.as | 4 +-
.../accessories/NumericOnlyTextInputBead.as | 84 ++++++++++++++++++++
.../accessories/PasswordInputBead.as | 56 +++++++++++++
.../staticControls/beads/PasswordInputBead.as | 55 -------------
.../accessories/NumericOnlyTextInputBead.js | 76 ++++++++++++++++++
.../accessories/PasswordInputBead.js | 43 ++++++++++
.../staticControls/beads/PasswordInputBead.js | 42 ----------
8 files changed, 263 insertions(+), 100 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54fb8d26/frameworks/as/basic-manifest.xml
----------------------------------------------------------------------
diff --git a/frameworks/as/basic-manifest.xml b/frameworks/as/basic-manifest.xml
index c7d1dfa..1eb0098 100644
--- a/frameworks/as/basic-manifest.xml
+++ b/frameworks/as/basic-manifest.xml
@@ -60,6 +60,7 @@
<component id="TextFieldItemRenderer" class="org.apache.flex.html.staticControls.supportClasses.TextFieldItemRenderer"/>
<component id="ScrollBar" class="org.apache.flex.html.staticControls.supportClasses.ScrollBar"/>
<component id="TextPromptBead" class="org.apache.flex.html.staticControls.beads.TextPromptBead" />
- <component id="PasswordInputBead" class="org.apache.flex.html.staticControls.beads.PasswordInputBead" />
+ <component id="NumericOnlyTextInputBead" class="org.apache.flex.html.staticControls.accessories.NumericOnlyTextInputBead" />
+ <component id="PasswordInputBead" class="org.apache.flex.html.staticControls.accessories.PasswordInputBead" />
</componentPackage>
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54fb8d26/frameworks/as/src/FlexJSUIClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/FlexJSUIClasses.as b/frameworks/as/src/FlexJSUIClasses.as
index a34d8ff..b5e0f5c 100644
--- a/frameworks/as/src/FlexJSUIClasses.as
+++ b/frameworks/as/src/FlexJSUIClasses.as
@@ -18,7 +18,6 @@
////////////////////////////////////////////////////////////////////////////////
package
{
-
/**
* @private
* This class is used to link additional classes into rpc.swc
@@ -27,6 +26,8 @@ package
*/
internal class FlexJSUIClasses
{
+ import org.apache.flex.html.staticControls.accessories.NumericOnlyTextInputBead; NumericOnlyTextInputBead;
+ import org.apache.flex.html.staticControls.accessories.PasswordInputBead; PasswordInputBead;
import org.apache.flex.html.staticControls.beads.AlertView; AlertView;
import org.apache.flex.html.staticControls.beads.CheckBoxView; CheckBoxView;
import org.apache.flex.html.staticControls.beads.ComboBoxView; ComboBoxView;
@@ -52,7 +53,6 @@ internal class FlexJSUIClasses
import org.apache.flex.html.staticControls.beads.TextInputView; TextInputView;
import org.apache.flex.html.staticControls.beads.TextInputWithBorderView; TextInputWithBorderView;
import org.apache.flex.html.staticControls.beads.TextPromptBead; TextPromptBead;
- import org.apache.flex.html.staticControls.beads.PasswordInputBead; PasswordInputBead;
import org.apache.flex.html.staticControls.beads.TitleBarMeasurementBead; TitleBarMeasurementBead;
import org.apache.flex.html.staticControls.beads.models.AlertModel; AlertModel;
import org.apache.flex.html.staticControls.beads.models.ArraySelectionModel; ArraySelectionModel;
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54fb8d26/frameworks/as/src/org/apache/flex/html/staticControls/accessories/NumericOnlyTextInputBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/accessories/NumericOnlyTextInputBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/accessories/NumericOnlyTextInputBead.as
new file mode 100644
index 0000000..b92a317
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/accessories/NumericOnlyTextInputBead.as
@@ -0,0 +1,84 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.html.staticControls.accessories
+{
+ import flash.events.TextEvent;
+
+ import org.apache.flex.core.CSSTextField;
+ import org.apache.flex.core.IBead;
+ import org.apache.flex.core.IStrand;
+ import org.apache.flex.events.Event;
+ import org.apache.flex.events.IEventDispatcher;
+ import org.apache.flex.html.staticControls.beads.ITextFieldView;
+
+ public class NumericOnlyTextInputBead implements IBead
+ {
+ public function NumericOnlyTextInputBead()
+ {
+ }
+
+ private var _strand:IStrand;
+
+ public function set strand(value:IStrand):void
+ {
+ _strand = value;
+
+ IEventDispatcher(value).addEventListener("viewChanged",viewChangeHandler);
+ }
+
+ private var _decimalSeparator:String = ".";
+ public function get decimalSeparator():String
+ {
+ return _decimalSeparator;
+ }
+ public function set decimalSeparator(value:String):void
+ {
+ if (_decimalSeparator != value) {
+ _decimalSeparator = value;
+ }
+ }
+
+ private function viewChangeHandler(event:Event):void
+ {
+ // get the ITextFieldView bead, which is required for this bead to work
+ var textView:ITextFieldView = _strand.getBeadByType(ITextFieldView) as ITextFieldView;
+ if (textView) {
+ var textField:CSSTextField = textView.textField;
+ textField.restrict = "0-9" + decimalSeparator;
+
+ // listen for changes to this textField and prevent non-numeric values, such
+ // as 34.09.94
+ textField.addEventListener(TextEvent.TEXT_INPUT, handleTextInput);
+ }
+ else {
+ throw new Error("NumericOnlyTextInputBead requires strand to have an ITextFieldView bead");
+ }
+ }
+
+ private function handleTextInput(event:TextEvent):void
+ {
+ var insert:String = event.text;
+ var caretIndex:int = (event.target as CSSTextField).caretIndex;
+ var current:String = (event.target as CSSTextField).text;
+ var value:String = current.substring(0,caretIndex) + insert + current.substr(caretIndex);
+ var n:Number = Number(value);
+ if (isNaN(n)) event.preventDefault();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54fb8d26/frameworks/as/src/org/apache/flex/html/staticControls/accessories/PasswordInputBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/accessories/PasswordInputBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/accessories/PasswordInputBead.as
new file mode 100644
index 0000000..9280317
--- /dev/null
+++ b/frameworks/as/src/org/apache/flex/html/staticControls/accessories/PasswordInputBead.as
@@ -0,0 +1,56 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.html.staticControls.accessories
+{
+ import org.apache.flex.core.CSSTextField;
+ import org.apache.flex.core.IBead;
+ import org.apache.flex.core.IStrand;
+ import org.apache.flex.events.Event;
+ import org.apache.flex.events.IEventDispatcher;
+ import org.apache.flex.html.staticControls.beads.ITextFieldView;
+
+ public class PasswordInputBead implements IBead
+ {
+ public function PasswordInputBead()
+ {
+ }
+
+ private var _strand:IStrand;
+
+ public function set strand(value:IStrand):void
+ {
+ _strand = value;
+
+ IEventDispatcher(value).addEventListener("viewChanged",viewChangeHandler);
+ }
+
+ private function viewChangeHandler(event:Event):void
+ {
+ // get the ITextFieldView bead, which is required for this bead to work
+ var textView:ITextFieldView = _strand.getBeadByType(ITextFieldView) as ITextFieldView;
+ if (textView) {
+ var textField:CSSTextField = textView.textField;
+ textField.displayAsPassword = true;
+ }
+ else {
+ throw new Error("PasswordInputBead requires strand to have a TextInputView bead");
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54fb8d26/frameworks/as/src/org/apache/flex/html/staticControls/beads/PasswordInputBead.as
----------------------------------------------------------------------
diff --git a/frameworks/as/src/org/apache/flex/html/staticControls/beads/PasswordInputBead.as b/frameworks/as/src/org/apache/flex/html/staticControls/beads/PasswordInputBead.as
deleted file mode 100644
index 4b27840..0000000
--- a/frameworks/as/src/org/apache/flex/html/staticControls/beads/PasswordInputBead.as
+++ /dev/null
@@ -1,55 +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.html.staticControls.beads
-{
- import org.apache.flex.core.CSSTextField;
- import org.apache.flex.core.IBead;
- import org.apache.flex.core.IStrand;
- import org.apache.flex.events.Event;
- import org.apache.flex.events.IEventDispatcher;
-
- public class PasswordInputBead implements IBead
- {
- public function PasswordInputBead()
- {
- }
-
- private var _strand:IStrand;
-
- public function set strand(value:IStrand):void
- {
- _strand = value;
-
- IEventDispatcher(value).addEventListener("viewChanged",viewChangeHandler);
- }
-
- private function viewChangeHandler(event:Event):void
- {
- // get the ITextFieldView bead, which is required for this bead to work
- var textView:ITextFieldView = _strand.getBeadByType(ITextFieldView) as ITextFieldView;
- if (textView) {
- var textField:CSSTextField = textView.textField;
- textField.displayAsPassword = true;
- }
- else {
- throw new Error("PasswordInputBead requires strand to have a TextInputView bead");
- }
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54fb8d26/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/accessories/NumericOnlyTextInputBead.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/accessories/NumericOnlyTextInputBead.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/accessories/NumericOnlyTextInputBead.js
new file mode 100644
index 0000000..278bf33
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/accessories/NumericOnlyTextInputBead.js
@@ -0,0 +1,76 @@
+/**
+ * Licensed 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.
+ */
+
+goog.provide('org.apache.flex.html.staticControls.accessories.NumericOnlyTextInputBead');
+
+
+
+/**
+ * @constructor
+ */
+org.apache.flex.html.staticControls.accessories.NumericOnlyTextInputBead =
+function() {
+
+ /**
+ * @private
+ * @type {Object}
+ */
+ this.promptElement;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.html.staticControls.accessories.NumericOnlyTextInputBead}
+ * @param {Object} value The new host.
+ */
+org.apache.flex.html.staticControls.accessories.NumericOnlyTextInputBead.
+prototype.set_strand = function(value) {
+ if (this.strand_ !== value) {
+ this.strand_ = value;
+ value.addEventListener('keypress',goog.bind(this.validateInput, this));
+ }
+};
+
+org.apache.flex.html.staticControls.accessories.NumericOnlyTextInputBead.
+prototype.validateInput = function(event) {
+
+ var code = event.charCode;
+
+ // backspace or delete
+ if (event.keyCode == 8 || event.keyCode == 46) return;
+
+ // tab or return/enter
+ if (event.keyCode == 9 || event.keyCode == 13) return;
+
+ // left or right cursor arrow
+ if (event.keyCode == 37 || event.keyCode == 39) return;
+
+ var key = String.fromCharCode( code );
+
+ var regex = /[0-9]|\./;
+ if( !regex.test(key) ) {
+ event.returnValue = false;
+ if(event.preventDefault) event.preventDefault();
+ return;
+ }
+ var cursorStart = event.target.selectionStart;
+ var cursorEnd = event.target.selectionEnd;
+ var left = event.target.value.substring(0,cursorStart);
+ var right = event.target.value.substr(cursorEnd);
+ var complete = left + key + right;
+ if (isNaN(complete)) {
+ event.returnValue = false;
+ if(event.preventDefault) event.preventDefault();
+ }
+};
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54fb8d26/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/accessories/PasswordInputBead.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/accessories/PasswordInputBead.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/accessories/PasswordInputBead.js
new file mode 100644
index 0000000..85779d2
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/accessories/PasswordInputBead.js
@@ -0,0 +1,43 @@
+/**
+ * Licensed 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.
+ */
+
+goog.provide('org.apache.flex.html.staticControls.accessories.PasswordInputBead');
+
+
+
+/**
+ * @constructor
+ */
+org.apache.flex.html.staticControls.accessories.PasswordInputBead =
+function() {
+
+ /**
+ * @private
+ * @type {Object}
+ */
+ this.promptElement;
+};
+
+/**
+ * @expose
+ * @this {org.apache.flex.html.staticControls.accessories.PasswordInputBead}
+ * @param {Object} value The new host.
+ */
+org.apache.flex.html.staticControls.accessories.PasswordInputBead.
+prototype.set_strand = function(value) {
+ if (this.strand_ !== value) {
+ this.strand_ = value;
+ value.element.type = 'password';
+ }
+};
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/54fb8d26/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/PasswordInputBead.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/PasswordInputBead.js b/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/PasswordInputBead.js
deleted file mode 100644
index f29acb8..0000000
--- a/frameworks/js/FlexJS/src/org/apache/flex/html/staticControls/beads/PasswordInputBead.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * Licensed 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.
- */
-
-goog.provide('org.apache.flex.html.staticControls.beads.PasswordInputBead');
-
-
-
-/**
- * @constructor
- */
-org.apache.flex.html.staticControls.beads.PasswordInputBead = function() {
-
- /**
- * @private
- * @type {Object}
- */
- this.promptElement;
-};
-
-/**
- * @expose
- * @this {org.apache.flex.html.staticControls.beads.PasswordInputBead}
- * @param {Object} value The new host.
- */
-org.apache.flex.html.staticControls.beads.PasswordInputBead.prototype.set_strand =
- function(value) {
- if (this.strand_ !== value) {
- this.strand_ = value;
- value.element.type = 'password';
- }
-};