Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    SpinnerItem ClickHandlers

    SmartClient Version: v9.1p_2015-07-30/PowerEdition Deployment (built 2015-07-30)

    I'm trying to add a FormItemClickHandler to the increase and decrease icons of a SpinnerItem. I tried to do something similar to the following code block but it doesn't seem to be working.

    Window window = new Window();
    window.setWidth(500);
    SpinnerItem spinnerItem = new SpinnerItem();
    DynamicForm form = new DynamicForm();
    form.setFields(spinnerItem);
    window.addItem(form);
    spinnerItem.getIncreaseIcon().addFormItemClickHandler(new FormItemClickHandler() {
    @Override
    public void onFormItemClick(FormItemIconClickEvent formItemIconClickEvent) {
    SC.say("Clicked");
    }
    });
    window.show();

    Alternatively, another solution to my problem is disabling the feature in SpinnerItem that automatically resets a value entered by the user when the value is outside of the defined min or max.

    So my questions are,
    - What is the correct way to add a click handler to the increase and decrease icons of a SpinnerItem?
    - How do you disable the auto-reset of a SpinnerItem if the entered value is greater than the max or less than the min?





    #2
    The max / min enforcement is applied on both values entered by interacting with the increase/decrease icons and those typed into the item. If you do not want this value to be enforced you can omit a max/min value altogether for unrestricted entry.

    If you want some other behavior, a changed handler might be appropriate.

    Can you explain exactly what you are trying to achieve and we will let you know what our recommended approach would be?

    Thanks
    Isomorphic Software

    Comment


      #3
      The component I am trying to make calls for a spinner item and an OK button.

      I want the user to be able to change the value of the spinner item using the keyboard, by clicking the increase and decrease icons or by entering the value manually from the keyboard. When entering the value by clicking or by the keyboard, I want the user to only be allowed to increment and decrement the value to the max and min. If they are entering the value manually, I want the entered value to remain in the box unless the user specifically does something to change the value (e.g presses the arrow keys).

      I also want to attach a validator to the spinner item. When the user presses the OK button, the handler will call the validator on the spinner item and display an error if the entered value is outside the specified min and max.

      Comment


        #4
        This isn't a built in mode, but you can achieve it:
        - do not apply a max or min value to your spinner (this allows for freeform text input of any numeric value)
        - use SpinnerItem.setNextValueHandler / setPreviousValueHandler to disallow values above your desired max/min. This will prevent the user from clicking the icons to increase/decrease beyond those values
        - use an explicit integerRange validator to enforce max/min on validation. This means when the user attempts to submit the form, if the hand-entered value is too high or too low a validation error will be raised for the field.

        Regards
        Isomorphic Software

        Comment


          #5
          Can you provide me with an example of how to properly use use of the NextValueHandler and the PreviousValueHandler? I've already tried something like the following and it only made the arrow keys and arrow icons of the SpinnerItem unresponsive. The SpinnerItem will also reject any value entered from the keyboard and automatically revert back to the default value.

          columnWidthSelecter = new SpinnerItem();
          columnWidthSelecter.setStep(STEP);
          columnWidthSelecter.setNextValueHandler(new NextValueHandler() {
          @Override
          public double execute(double current, double step) {
          double nextVal = current + step;
          nextVal = (nextVal > MAX_PIXEL_WIDTH)? MAX_PIXEL_WIDTH : nextVal;
          return nextVal;
          }
          });
          columnWidthSelecter.setPreviousValueHandler(new PreviousValueHandler() {
          @Override
          public double execute(double current, double step) {
          double prevVal = current - step;
          preval = (prevVal < MIN_PIXEL_WIDTH)? MIN_PIXEL_WIDTH : prevVal;
          return prevVal;
          }
          });

          Comment


            #6
            The 'next' handler needs to increase the value, and the 'previous' handler needs to decrease the value.
            For the previous handler, the "step" passed in is already a negative value (-this.step) - so you want to add it to curent, rather than subtracting it from current.

            So something like this:

            Code:
                    SpinnerItem spinnerItem = new SpinnerItem();
                    
                    spinnerItem.setStep(1);
                    spinnerItem.setNextValueHandler(new NextValueHandler() {
                        
                        @Override
                        public double execute(double currentValue, double step) {
                            double nextVal = currentValue + step;
                            nextVal = (nextVal > 10)?10: nextVal;
                            return nextVal;
                        }
                    });
                    spinnerItem.setPreviousValueHandler(new PreviousValueHandler() {
                        
                        @Override
                        public double execute(double currentValue, double step) {
            
                            double prevVal = currentValue + step;
                            prevVal = (prevVal < 0)? 0 : prevVal;
                            return prevVal;
                        }
                    });

            Comment

            Working...
            X