10 Replies Latest reply on Dec 6, 2009 6:29 PM by P.o.l.a.c.o

    Limit numericstepper to maximum of 10

    Vanden_B Level 1

      Hi All,

       

      I have a Numericstepper with maximum="10" and maxChars="2".
      But the problem is that a number of 99 can be filled in within the NumericStepper (ie. the input textfield) with the keyboard.
      I want to show an alert if the user has filled in a value > 10. Therefore I think I need to use a focusOut to check on the value and eventually throw a alert. A change event only is dispatched when usings the arrows.

       

      Is this the right approach or is there another way/event to achieve this (and maybe an example)?

        • 1. Re: Limit numericstepper to maximum of 10
          msakrejda Level 4

          Do you need maxChars? What happens when you remove that and keep just the maximum?

          • 2. Re: Limit numericstepper to maximum of 10
            P.o.l.a.c.o Level 1

            I think that if you set the maximum property to 10 if the user sets 99 then when the component loose focus it will automatically set the value to 10 since it has a method that checks that kind of things. The method is "checkValidValue" the bad thing about this method is that can not be overrided so you can't deactivate that kind of "automatic number rounding". You could also disable user keyboard editing to not allow keyboard inputs.

            • 3. Re: Limit numericstepper to maximum of 10
              harihisu Level 2

              If user type in 99 and leave the NumericStepper, its value will be checked and return to 10. Then you don't need to do that again.

              • 4. Re: Limit numericstepper to maximum of 10
                Vanden_B Level 1

                Thanks for the replies, but it's not quite what I'm looking for.

                Remove maxChars is not an option, if this is the case, the user can fill "unlimited" charactes.


                I want to show an alert to the user if he/she filled in > 10 and loose focus. For example, when the user clicks on a button. Because I want the user explicitly note that the value is changed to 10.

                • 5. Re: Limit numericstepper to maximum of 10
                  P.o.l.a.c.o Level 1

                  The problem you are facing is exactly the same porblem I have.

                  I think that the solution would be to make the "checkValidValue" protected instead of private so we could override it.

                  Then would be possible to add a validator to check if the entered value is correct or not.

                  We could ask for this feature to Adobe, however I don't think you will get it done soon.

                  I couldn't find a nice workarround for this issue.

                  Please post it if you find it.

                  • 6. Re: Limit numericstepper to maximum of 10
                    funkysoul Level 4

                    Here a solution I have in mind, it's not test though but you can give it a try:

                     

                    1. Remove the maxValue from your Numeric stepper

                     

                    2. add a change event to the numeric stepper which calls the method "validateStepper", I assume that your numeric stepper has an ID.

                     

                    3. Write following AS3 code inside the script tag

                     

                    private function validateStepper(e:Event):void

                    {

                         if(nummericSteppperID.value > 10)

                         {

                               showAlert(); // this would be the call to your method that displays the desired message

                               numericStepperID.value = 10;

                         }

                         else

                         {

                              //do nothing

                         }

                    }

                     

                    Let us know if this worked for you.

                    • 7. Re: Limit numericstepper to maximum of 10
                      Vanden_B Level 1

                      Thanks for the idea, but it does not work.
                      The default value of the property "maximum" is 10. And it replaces the inserted value to 10 before dispatching the change event...


                      The solution I use now is:


                      <mx:NumericStepper id="stepper" stepSize="1" maxChars="2" minimum="0" focusOut="validateStepper(event)" />

                       

                      private function validateStepper(e:FocusEvent):void
                         {
                          if (e.target is UITextField)
                          {
                           var valueToCheckStr:String = UITextField(e.target).text;
                           var valueToCheck:Number = Number(valueToCheckStr);

                           if (valueToCheck > 10)
                           {
                            Alert.show("stepper more the 10!");
                           }
                          }
                          else
                          {
                           // catches NumericStepper change-event, do nothing, because value is set to 10 already
                          }
                         }

                       

                      This will work, but let me know if a better solution is available!

                      • 8. Re: Limit numericstepper to maximum of 10
                        P.o.l.a.c.o Level 1

                        I have extended the numeric stepper to make possible to notify if the automatic rounding will be performed.

                        Here I have attached a rough demo.

                        Hope this could help someone.

                        (the validator has nothing has no effect on the demo and is not necesary to be used)

                         

                        greetings,

                        Polaco.

                         

                         

                        ..Maybe someone from Adobe reads this posts and rewrite the NumericStepper to make it more extensible. Or we should add this as a request on the bug reporting section.

                        • 9. Re: Limit numericstepper to maximum of 10
                          Peter deHaan Level 4

                          Your best bet would be to file a bug/enhancement at http://bugs.adobe.com/flex/.

                           

                          Peter

                          • 10. Re: Limit numericstepper to maximum of 10
                            P.o.l.a.c.o Level 1

                            Hi Peter,

                             

                            Here is the enhancement request created:

                            https://bugs.adobe.com/jira/browse/SDK-24577

                             

                            Would be nice for people participating of this tread to vote it if find this useful.

                             

                            thanks a lot,

                             

                            Polaco.