Flex中利用NumberValidator类的Boolean allowNegative属性设置是否允许负数的例子

By Minidxer | August 31, 2008

接下来的例子演示了Flex中如何利用NumberValidator类的Boolean allowNegative属性,设置是否允许负数。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application name="NumberValidator_allowNegative_test"
  3.         xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         layout="vertical"
  5.         verticalAlign="middle"
  6.         backgroundColor="white">
  7.  
  8.     <mx:Script>
  9.         <![CDATA[
  10.             import mx.controls.Alert;
  11.             import mx.events.ValidationResultEvent;
  12.  
  13.             private function numberValidator_invalid(evt:ValidationResultEvent):void {
  14.                 Alert.show(evt.message);
  15.             }
  16.  
  17.             private function numberValidator_valid(evt:ValidationResultEvent):void {
  18.                 Alert.show(evt.type);
  19.             }
  20.         ]]>
  21.     </mx:Script>
  22.  
  23.     <mx:ApplicationControlBar dock="true">
  24.         <mx:Form styleName="plain">
  25.             <mx:FormItem label="allowNegative:">
  26.                 <mx:CheckBox id="checkBox"
  27.                         selected="true" />
  28.             </mx:FormItem>
  29.         </mx:Form>
  30.     </mx:ApplicationControlBar>
  31.  
  32.     <mx:NumberValidator id="numberValidator"
  33.             allowNegative="{checkBox.selected}"
  34.             source="{textInput}"
  35.             property="text"
  36.             trigger="{button}"
  37.             triggerEvent="click"
  38.             invalid="numberValidator_invalid(event);"
  39.             valid="numberValidator_valid(event);" />
  40.  
  41.     <mx:HBox defaultButton="{button}">
  42.         <mx:TextInput id="textInput"
  43.                 restrict="0-9.-"
  44.                 maxChars="10" />
  45.         <mx:Button id="button"
  46.                 label="validate" />
  47.     </mx:HBox>
  48.  
  49. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Flex | No Comments » | Tags: , ,

你可能还对下列文章感兴趣:

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts