2 Replies Latest reply on Sep 17, 2009 7:38 AM by Mongolian Beef

    NumericStepper focusing/highlighting issue

    Mongolian Beef Level 1

      Hi,

       

      I have extended NumericStepper to format all values to have 2 digits, hence any number from 0 through 9 will be prepadded with 0.  The highest these numbers will go is 50.  On creation complete, I set the focus to this stepper.  When I drop this stepper in a datagrid, once I click on a cell that uses this stepper, it renders the stepper properly.  However, when it focuses on the stepper, it only highlights the first digit of the two digits if the number was prepadded.  For any other number greater than 9, it highlights both digits properly.  For example, say I initialize my stepper to be 10.  When I click on the cell that has this stepper, the focus is on the stepper and in which highlights the entire number 10.  If I initialize the stepper to 8, when I click on this cell, the number 08 shows up properly but the focusing only highlights the 0.  It does not highlight the 8.  It seems as though the focus manager didn't know the value of the stepper was prepadded with a 0.  Any ideas on how to debug this?  Below is my stepper extension:

       

      ****************************************************************************

      public class FormattedNumericStepper extends NumericStepper {

       

              public function DoubleDigitNumericStepper() {
                  super();
                  addEventListener(Event.CHANGE, handleChange);
              }

       


              private function handleChange(e:Event=null):void {
                  var txt:TextInput = mx_internal::inputField;
                 
                  if (txt.text.length == 1) {
                      var formattedString:String = "0" + txt.text;
                      txt.text = formattedString;               
                  }           
              }
             
         
              override protected function commitProperties():void {
                  super.commitProperties();
                  handleChange();           
              }
      }

      *****************************************************************************

        • 1. Re: NumericStepper focusing/highlighting issue
          Flex harUI Adobe Employee

          Try calling setSelection on focusIn

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: NumericStepper focusing/highlighting issue
            Mongolian Beef Level 1

            Hi,

             

            Thanks for the reply.  I tried what you suggested in my numericstepper extension (bolded below) but it seems to not do anything.  Any other ideas?  Thanks.

             

            ****************************************************************************

            public class FormattedNumericStepper extends NumericStepper {

             

                    public function DoubleDigitNumericStepper() {
                        super();
                        addEventListener(Event.CHANGE, handleChange);

                        addEventListener(FocusEvent.FOCUS_IN, focusingHandler);
                    }

             


                    private function handleChange(e:Event=null):void {
                        var txt:TextInput = mx_internal::inputField;
                       
                        if (txt.text.length == 1) {
                            var formattedString:String = "0" + txt.text;
                            txt.text = formattedString;               
                        }           
                    }
                   
               
                    override protected function commitProperties():void {
                        super.commitProperties();
                        handleChange();           
                    }

             

                    private function focusingHandler(e:Event=null):void {
                        var txt:TextInput = mx_internal::inputField;
                        txt.setSelection(0, 1);  // or end index of 2, still doesn't work
                    }

            }

            *****************************************************************************