Announcement

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

    question re. focus handling in splitpane handset mode

    Hello,

    i have a splitpane with a grid to the left, and a form to the right, and i'm having trouble getting focus right in handset mode.
    --

    I have a clickhandler on the grid. so when a row in the grid is clicked i do showDetailPane on the splitpane and then i have some logic to decide which formitem that should have focus.

    this works fine in desktop mode, but in handset mode it seems that since the form isn't drawn and visible yet (the detail pane),
    any calls to any of the focus methods in the form are ignored.

    It's in the context of the clickhandler that i have the listgridrecord, and i know what to focus on, so i'm not sure what to do. Is there
    some callback in the form that i can latch on to and have my focus logic there?

    Pointers appreciated.

    #2
    If you focusInItem() on a form that is not yet drawn, when it is drawn, focus goes to that item when the form as a whole receives focus.

    You can add a DrawHandler to the form to make it take over focus when drawn, or a visibilityChanged handler if you want pane transitions to always grab focus for the form.

    Comment


      #3
      Well, it doesn't work for me in this particular form. I made a testcase and i will elaborate a bit, if you don't mind. I am running in the 13 beta from august 18 or so.

      ---
      Basically, i show/hide items in my form when users are about to edit it (because i have headers that display the same data in view mode and i don't want to show the same thing twice).

      DESKTOP MODE
      If a field is hidden, then shown - focus doesn't work unless i do a redraw first. Code is below. Sometimes it focuses, but on the wrong field, not sure why. See the clickhandler below. I am not sure if this is perhaps working as intended?

      HANDSET MODE
      In handset mode (uncomment first row below), the item does not get focus at all for in the below code. It also does not matter if i remove all the show/hide calls to my text2 formitem, i get no focus.


      Code below, pointers appreciated. I sure hope i've made a stupid mistake :)


      Code:
      public void onModuleLoad() {
      //        Browser.setIsHandset(true);
      
              DynamicForm form = new DynamicForm();
              form.setTitleOrientation(TitleOrientation.TOP);
              form.setNumCols(1);
      
             TextItem text = new TextItem("text", "Text");
              FormItem text2 = new TextItem("text2", "Apple");
              text2.hide();
              FormItem text3 = new TextItem("text3", "Banana");
      
              form.setItems(text, text2, text3);
      
              Button button = new Button("Edit");
      
              ListGrid grid = new ListGrid();
              grid.setFields(new ListGridField("text", "Text"), new ListGridField("text2", "Apples") , new ListGridField("text3", "Bananas"));
              grid.setRecords(getRecords());
      
              Layout navPane = (VLayout) new VLayout().setWidth100().setHeight100();
              navPane.setHeight100();
              navPane.setMembersMargin(30);
              navPane.addMembers(button, grid);
      
              SplitPane pane = new SplitPane(navPane, form);
              pane.setWidth100().setHeight100();
      
              button.addClickHandler(clickEvent -> {
                  text2.show();
                  form.redraw();//must happen or newly shown field won't have focus in desktop mode
                  text2.focusInItem();//does NOT work without the redraw above, and does NOT work in mobile at all
      
                  pane.showDetailPane();
              });
              pane.draw();
          }
      
          private ListGridRecord[] getRecords(){
              int rows = 5;
              ListGridRecord[] recs = new ListGridRecord[rows];
              for(int i = 0 ; i < rows ; i++){
                  recs[i] = createRecord("Text " + i, "Apple Row " + i, "Banana Row" + i);
              }
              return recs;
          }
      
          public static ListGridRecord createRecord(String text1, String text2, String text3) {
              ListGridRecord record = new ListGridRecord();
              record.setAttribute("text", text1).setAttribute("text2", text2).setAttribute("text3", text3);
              return record;
          }

      Comment


        #4
        Thanks for the test case
        There are two things going on here:
        - The fact that you can't focus in the item synchronously after changing its visibility without an explicit call to 'redraw()' is a bug.
        We've fixed this and the fix will be in the next nightly build (dated Aug 26 or above, 13.0d branch)
        - The fact that you can't focus in the item in handset mode with the above code is an application coding issue.
        These lines:
        Code:
        text2.focusInItem();
        pane.showDetailPane();
        ...are in the wrong order. The detail pane (the form containing text2) is hidden until the showDetailPane() call, so you're trying to put focus into a hidden item, then show it. If you call showDetailPane() first, then focusInItem() it should work for you in handset mode

        Regards
        Isomorphic Software

        Comment


          #5
          OK, that sounds great.

          Regarding the ordering of the lines - This is going to sound stupid, but i could swear that i've seen somewhere in the javadocs a comment along the lines "if you call focus, the item will get focus when the form becomes visible", or something along that line.

          So i thought that the "focusinitem" was that you kind of told the form and when the form gets focus, it would then give the focus on the item.
          Thanks, i'll try to reverse the order somehow.

          Comment

          Working...
          X