2 Replies Latest reply on Feb 8, 2011 4:53 AM by JabbyPandaUA

    Help required on simple validations for Flex Numeric Stepper

    Rajeshb_Flash Level 1


      I need a small help in Flex Numeric Stepper validation.

      I have setted a min value to 1 and max value to 10, Now my requirement  is when ever user can enter a value other than the range between 1 - 10,  i want to display an alert saying "please enter the val's between 1 and  10". I want this scenario to be success in all possible event listeners  like Keyboardevents/mouseevents/default numeric stepper events.  Actually i am failing to produce an alert if i typed the value as "0".  Other than this everything is fine.

      i am attaching the code as well for reference. i need solution asap.
      your help will be appreciated.





      private var nsTextInput:Number;
      private var nsTextInputOld:Number;


      private var ns:NumericStepper = new NumericStepper();


      ns.minimum = 1;
      ns.maximum = 10;
      ns.addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteNs);               


      private function creationCompleteNs(event:FlexEvent):void{
          var textInput:TextInput = event.currentTarget.getChildAt(0) as TextInput;
          textInput.addEventListener(KeyboardEvent.KEY_UP, keyUPTextInput);
          textInput.addEventListener(FocusEvent.FOCUS_OUT, focusOutTextInput);
          textInput.addEventListener(FocusEvent.FOCUS_IN, focusInTextInput);


                  private function keyUPTextInput(event:KeyboardEvent):void
                      nsTextInput = event.target.text;
                  private function focusInTextInput(event:FocusEvent):void
                      nsTextInputOld = event.target.text;
                  private function focusOutTextInput(event:FocusEvent):void
                      if((nsTextInput<ns.minimum || nsTextInput>ns.maximum) && nsTextInput){
                          Alert.show("Please provide values from "+ns.minimum+" to "+ns.maximum+".","Alert!");
                          event.target.value = nsTextInputOld;
                      nsTextInput = null;