<?xml version="1.0"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark">
<fx:Script><![CDATA[
import mx.controls.Alert;
private var isProcessRequiredOnFocusOut:Boolean = true;
private function addEventListeners():void {
numericStepper.addEventListener(KeyboardEvent.KEY_DOWN, checkRange, true);
numericStepper.addEventListener(FocusEvent.FOCUS_OUT, checkRange, true);
}
private function checkRange(event:Event):void {
if (event is KeyboardEvent && (event as KeyboardEvent).keyCode == Keyboard.ENTER) {
isProcessRequiredOnFocusOut = false;
processRangeCheck();
}
else if (event is FocusEvent && (event as FocusEvent).type == FocusEvent.FOCUS_OUT
&& isProcessRequiredOnFocusOut) {
processRangeCheck();
}
}
private function processRangeCheck():void {
var typedNumber:Number = Number(numericStepper.textDisplay.text);
if (typedNumber > numericStepper.maximum || typedNumber < numericStepper.minimum) {
Alert.show("The typed number " + typedNumber + " is out of range.", "Out of Range Warning");
}
isProcessRequiredOnFocusOut = true;
}
]]></fx:Script>
<s:Panel title="Show Error message when Typed Number is out of range in Numeric Stepper."
verticalCenter="0" horizontalCenter="0">
<s:VGroup paddingTop="10" paddingLeft="10"
paddingRight="10" paddingBottom="10"
horizontalAlign="center"
width="100%">
<s:Label text="The valid range of Numeric Stepper is 10-20."/>
<s:NumericStepper id="numericStepper"
minimum="10"
maximum="20"
creationComplete="addEventListeners()"/>
<s:Button label="Click here to focus out from the Text Input of Numeric Stepper."/>
</s:VGroup>
</s:Panel>
</s:Application>
3条答案
按热度按时间w8ntj3qf1#
当用户按下ENTER键或
NumericStepper
的text input
中的focus out
时,您可以使用逻辑检查输入的数字是否在以下范围内:yr9zkbsy2#
要根据
NumericStepper
组件的 maximum 和 minimum 值检查输入的值,有一种直观的方法, -在输入时,可以在NumericStepper
示例的textField
属性上侦听KEY_UP
的键盘事件:vhmi4jdf3#
使用mx_internal属性引用NumericStepper的inputField