Announcement

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

    BlurHandler and picker icon

    Greetings!

    On my DynamicForm I have one DateItem with setUseTextField(true). I added BlurHandler to it and my question is if I can somehow know in that BlurHandler, that picker icon of that same DateItem was clicked?
    Or in another words: I don't want BlurHandler to fire if I just open date picker to select another date.
    Is this possible?

    Code:
        @Override
        public void onModuleLoad() {
            DynamicForm form = new DynamicForm();
    
            DateItem dateItem = new DateItem("toDate", "TO DATE");
            dateItem.setUseTextField(true);
            dateItem.setShowPickerIcon(true);
            dateItem.addBlurHandler(new BlurHandler() {
                
                @Override
                public void onBlur(BlurEvent event) {
                    // how to avoid this when picker icon is pressed
                    System.out.println("I'm in BlurHandler");
                }
            });
            
            TextItem textItem = new TextItem("anotherField", "ANOTHER FIELD");
            
            form.setItems(dateItem, textItem);
    
            com.smartgwt.client.widgets.Window window = new com.smartgwt.client.widgets.Window();
            window.setWidth(500);
            window.setHeight(300);
            window.setAutoCenter(true);
            window.setIsModal(true);
            window.addItem(form);
            window.show();
            
            FormItemIcon icon = dateItem.getIcon("picker");
            if (icon != null) {
                icon.setTabIndex(-1);
            } else {
                System.out.println("no picker");
            }
        }


    I'm using :
    SmartGWT 3.1p
    SmartClient Version: v8.3_2012-11-20/LGPL Development Only (built 2012-11-20)
    Chrome 26.0.1410.64 m

    #2
    Use the EditorExit event instead.

    Comment


      #3
      Originally posted by Isomorphic View Post
      Use the EditorExit event instead.
      I tried EditorExitHandler but result is the same. When picker icon is clicked, event is fired. Any other idea maybe?

      Code:
      dateItem.addEditorExitHandler(new EditorExitHandler() {
                  
                  @Override
                  public void onEditorExit(EditorExitEvent event) {
                      System.out.println("I'm in EditorExitHandler");
                  }
              });

      Comment


        #4
        Sorry, EditorExit will not fire if keyboard focus moves to a FormItemIcon (whereas Blur will). EditorExit *will* fire if the DateChooser is opened.

        If you have logic that needs to avoid firing in the circumstance, please explain the actual *purpose* of this logic and we can probably suggest an alternative approach.

        Comment


          #5
          OK, I will try to explain what we are actually trying to achieve. On some FormItem we would like to add picker icon. Click on that icon will open up our own picker for user to choose some value. But that is not the only way user can set value to FormItem, user can just write something in it and move to another field with TAB or mouse click. In that case, we need to verify if value in field is entered correctly - today this verification is done in BlurHandler. So we don't want this BlurHandler to "fire" if the picker for that same FormItem is opened.
          But it must fire whenever user changes value and moves focus to another field or clicks picker icon on some other FormItem.

          Comment


            #6
            Declare a validator instead.

            Comment


              #7
              Could you be more specific, how this will help me in my case.
              As far as I can see in documentation, if I set custom validator and set formItem.setValidateOnExit(true)
              it would be the same as adding EditorExitHandler.
              And if this is correct, why would be better to use validator if validation will occur again when picker is opened?

              Comment


                #8
                The validation logic will run as the picker is shown, but also as the user actually exits the field (goes to another field, for example), clearing the error if one is detected.

                It's true that, if the user specifically input invalid data before launching the picker, the field will show an error in the background while the user interacts with the picker. This doesn't seem like it's necessarily wrong behavior, nor important to fix. However if you really really want to avoid this, you could always set a flag in the click handler that launches the picker, which your validator could consult in order to know to always let the value pass while the picker is showing.

                Comment

                Working...
                X