1. #1
    Sencha User
    Join Date
    Sep 2009
    Posts
    289
    Vote Rating
    0
    diegolovison is on a distinguished road

      0  

    Default how focus textfield that was added in a window?

    how focus textfield that was added in a window?


    how focus textfield that was added in a window?

    Code:
    public class XEntryPoint implements EntryPoint {
    
        @Override
        public void onModuleLoad() {
    
            final TextField<String> field = new TextField<String>();
            field.focus();
    
            final FormPanel panel = new FormPanel();
            panel.add(field);
    
            final Window w = new Window();
            w.setSize(400, 400);
            w.add(panel);
            w.show();
        }
    }
    I tryed add onRender listener on text field and call the method focus, and other ways.. but dont have success

    regards

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    w.setFocusWidget(field);
    for example.

    Else you need to focus it after showing the window, probably in a DeferredCommand.

  3. #3
    Sencha User
    Join Date
    Sep 2009
    Posts
    289
    Vote Rating
    0
    diegolovison is on a distinguished road

      0  

    Default


    dont work...

    I set the focusWidget, added a listener after showing the window and call the focus method that is present in a Window class...

    but dont work...

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    You directly need to call setFocsuWidget before showing the window OR you need to focus the widget in a DeferredCommand after showing the window

  5. #5
    Sencha User
    Join Date
    Sep 2009
    Posts
    289
    Vote Rating
    0
    diegolovison is on a distinguished road

      0  

    Default


    dont work....
    you can try too...

    ff 3.6.11
    gwt 2.0.4
    gxt 2.2.0

  6. #6
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    I just tested both solutions and they work fine for me in FF 3.6.11

  7. #7
    Sencha User
    Join Date
    Sep 2009
    Posts
    289
    Vote Rating
    0
    diegolovison is on a distinguished road

      0  

    Default


    thanks

  8. #8
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Code:
    final TextField<String> field = new TextField<String>();
    
            final FormPanel panel = new FormPanel();
            panel.add(field);
    
            final Window w = new Window();
            w.setSize(400, 400);
            w.add(panel);
            w.show();
    
            DeferredCommand.addCommand(new Command() {
              public void execute() {
                field.focus();
              }
            });
    or

    Code:
    TextField<String> field = new TextField<String>();
    
            final FormPanel panel = new FormPanel();
            panel.add(field);
    
            final Window w = new Window();
            w.setSize(400, 400);
            w.add(panel);
            w.setFocusWidget(field);
            w.show();

  9. #9
    Sencha User
    Join Date
    Sep 2009
    Posts
    289
    Vote Rating
    0
    diegolovison is on a distinguished road

      0  

    Default


    its a login window, so for me work with this code....

    Code:
    public class LoginWindow extends Window {
    
        @Override
        public void show() {
            DeferredCommand.addCommand(new Command() {
    
                @Override
                public void execute() {
                    setFocusWidget(textFieldUsuario);
                }
            });
            super.show();
        }
    }

  10. #10
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    You really dont want to use that code. It does not make sense to defer the setFocusWidget call

Similar Threads

  1. Cannot get focus into a TextField in a popup window?
    By the.jxc in forum Ext 3.x: Help & Discussion
    Replies: 20
    Last Post: 11 Aug 2010, 6:09 AM
  2. [Solved] Window.show and TextField focus
    By mohaaron in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 10 Aug 2010, 2:56 PM
  3. [CLOSED]Listeners focus lost when a new item is added.
    By nairep in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 2 Mar 2010, 1:02 PM
  4. Focus is not in textfield after changing the window
    By lukas.wappler in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 8 Aug 2008, 5:18 AM
  5. Replies: 1
    Last Post: 14 Jul 2008, 10:16 PM

Thread Participants: 1