GWT: Textbox doesn't show Cursor on Ipad

∥☆過路亽.° 提交于 2021-01-29 16:42:50

问题


I am trying to implement a Textbox that can show fractions with GWT. Therefor I have an Canvas were I can draw what I want and receive KeyEvents and MouseEvents.

But on Ipad (Safarie and Chrome) the software keyboard does not show, so I created an Composite and combined the Canvas with a Textbox witch gets the focus after each key or mouse Event on the Canvas.

But the softkeyboard does not show up every time so I tried a bit and can see, that the Textbox seems to get the focus (it gets a blue boarder) but does not always show the cursor.

This does not happen on my Notebook.

Is there any difference between being focused and showing the cursor?

I tried:

  • Setting the Cursor position
  • set the Text of the Textbox.

Any help would be appreciated, Christoph

    public void setFocus(boolean b) {
    //  if (hasFocus) {
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
            public void execute () {
                t.setFocus(b);
            }
           });
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {
            public void execute () {
                box.setFocus(true);
                box.setText("x");
                box.setCursorPos(0);
//              box.setVisible(false);
//              box.setVisible(true);
            }
           });

  //        t.setFocus(b);
//      box.setFocus(b);

//      }
    }


回答1:


The iOS browsers don't allow the focus to be set programmatically unless directly in response to a user interaction (i.e. a touch). I believe the reason is to prevent websites bringing up the virtual keyboard for no reason.

The downside is that it clobbers setFocus() for websites that want to use it for legitimate reasons. You can't call setFocus() in a deferred command because that doesn't count as a direct response to the user interaction.

(To be more precise, you can call setFocus() in a deferred command, but it won't have the desired effect as you found out.)



来源:https://stackoverflow.com/questions/62200524/gwt-textbox-doesnt-show-cursor-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!