You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cf...@apache.org on 2013/01/21 19:30:10 UTC
svn commit: r1436537 - in /flex/sdk/branches/develop:
frameworks/projects/spark/src/spark/components/NumericStepper.as
mustella/tests/gumbo/components/NumericStepper/Properties/NumericStepper_Properties.mxml
Author: cframpton
Date: Mon Jan 21 18:30:10 2013
New Revision: 1436537
URL: http://svn.apache.org/viewvc?rev=1436537&view=rev
Log:
FLEX-33064. Numeric Stepper didn't always handle NaN cases correctly.
Modified:
flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/NumericStepper.as
flex/sdk/branches/develop/mustella/tests/gumbo/components/NumericStepper/Properties/NumericStepper_Properties.mxml
Modified: flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/NumericStepper.as
URL: http://svn.apache.org/viewvc/flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/NumericStepper.as?rev=1436537&r1=1436536&r2=1436537&view=diff
==============================================================================
--- flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/NumericStepper.as (original)
+++ flex/sdk/branches/develop/frameworks/projects/spark/src/spark/components/NumericStepper.as Mon Jan 21 18:30:10 2013
@@ -798,25 +798,37 @@ public class NumericStepper extends Spin
inputValue = dataFormatter.parseNumber(textDisplay.text);
}
-
- if ((textDisplay.text && textDisplay.text.length != value.toString().length)
- || textDisplay.text == "" || (inputValue != value &&
- (Math.abs(inputValue - value) >= 0.000001 || isNaN(inputValue))))
+
+ if ((textDisplay.text && textDisplay.text.length != value.toString().length) ||
+ textDisplay.text == "" ||
+ (isNaN(inputValue) && !isNaN(value)) ||
+ (!isNaN(inputValue) && isNaN(value)) ||
+ (inputValue != value && (Math.abs(inputValue - value) >= 0.000001)))
{
- setValue(nearestValidValue(inputValue, snapInterval));
-
+ var newValue:Number = !isNaN(inputValue) ? nearestValidValue(inputValue, snapInterval) : NaN;
+ setValue(newValue);
+
// Dispatch valueCommit if the display needs to change.
- if (value == prevValue && inputValue != prevValue)
+ if (!valuesEqual(value, prevValue) || !valuesEqual(inputValue, prevValue))
dispatchEvent(new FlexEvent(FlexEvent.VALUE_COMMIT));
}
if (dispatchChange)
{
- if (value != prevValue)
+ if (!valuesEqual(value, prevValue))
dispatchEvent(new Event(Event.CHANGE));
}
}
-
+
+ /**
+ * @private
+ * Helper method that returns true if num1 equal to num2.
+ */
+ private function valuesEqual(num1:Number, num2:Number):Boolean
+ {
+ return ((!isNaN(num1) && !isNaN(num2) && num1 == num2) || (isNaN(num1) && isNaN(num2)));
+ }
+
/**
* @private
* Helper method that returns a number corresponding
Modified: flex/sdk/branches/develop/mustella/tests/gumbo/components/NumericStepper/Properties/NumericStepper_Properties.mxml
URL: http://svn.apache.org/viewvc/flex/sdk/branches/develop/mustella/tests/gumbo/components/NumericStepper/Properties/NumericStepper_Properties.mxml?rev=1436537&r1=1436536&r2=1436537&view=diff
==============================================================================
--- flex/sdk/branches/develop/mustella/tests/gumbo/components/NumericStepper/Properties/NumericStepper_Properties.mxml (original)
+++ flex/sdk/branches/develop/mustella/tests/gumbo/components/NumericStepper/Properties/NumericStepper_Properties.mxml Mon Jan 21 18:30:10 2013
@@ -945,6 +945,31 @@
</body>
</TestCase>
+ <TestCase testID="NumericStepper_NaN" keywords="[NumericStepper,FLEX-33064]" description="Test NumericStepper handling of NaN values">
+ <setup>
+ <ResetComponent target="myNS" className="comps.myCustomNS" waitEvent="updateComplete"/>
+ <SetProperty target="myNS" propertyName="minimum" value="10" />
+ <SetProperty target="myNS" propertyName="value" value="20" />
+ <SetProperty target="myNS" propertyName="maximum" value="50" waitEvent="updateComplete" waitTarget="myNS"/>
+ </setup>
+ <body>
+ <!-- focusIn to NumericStepper and delete the current value then focusOut to commit NaN -->
+ <DispatchKeyEvent key="TAB" waitEvent="focusIn" waitTarget="myNS" />
+ <DispatchKeyEvent keys="[DELETE, DELETE, TAB]" waitEvent="focusOut" waitTarget="myNS" />
+ <AssertPropertyValue target="myNS" propertyName="value" value="NaN" />
+
+ <!-- focus back in and enter 777 which is more than max of 50 -->
+ <DispatchKeyEvent keys="[TAB, TAB]" waitEvent="focusIn" waitTarget="myNS" />
+ <DispatchKeyEvent char="777" waitEvent="updateComplete" waitTarget="myNS.textDisplay"/>
+ <AssertPropertyValue target="myNS.textDisplay" propertyName="text" value="777"/>
+
+ <!-- TAB will focusOut which will commit the value of 777 -->
+ <DispatchKeyEvent key="TAB" waitEvent="valueCommit" waitTarget="myNS" />
+ <!-- which is changed to the max of 50 -->
+ <AssertPropertyValue target="myNS" propertyName="value" value="50" />
+ </body>
+ </TestCase>
+
</testCases>
</UnitTester>