1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    19
    Vote Rating
    0
    listirer is on a distinguished road

      0  

    Default Simulate button pressed for a Dialog

    Simulate button pressed for a Dialog


    I have crated a Dialog via MessageBox (prompt method) and added a KeyListener to the TextField.
    How can I simulate the pressed of button OK?
    The onButtonPressed method of Dialog is protected...

    Code:
    public static MessageBox promptMessage(String title, String message,
                                       Listener<MessageBoxEvent> callback) {
    final MessageBox box = MessageBox.prompt(title, message, callback);
    
    final Button okButton = box.getDialog().getButtonById(Dialog.OK);
    okButton.disable();
    
    final TextField<String> textBox = box.getTextBox();
    textBox.addKeyListener(new KeyListener() {
    
        @Override
        public void componentKeyPress(ComponentEvent event) {
            if (okButton.isEnabled()
                    && event.getKeyCode() == KeyCodes.KEY_ENTER) {
                box.close();
            }
        }
    });
    
    box.addListener(Events.OnKeyUp, new Listener<MessageBoxEvent>() {
    
        @Override
        public void handleEvent(MessageBoxEvent be) {
            String value = textBox.getValue();
            if (value == null || value.trim().equals("")) {
                okButton.disable();
            } else {
                okButton.enable();
            }
        }
    });
    return box;
    }

  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


    Why would you like to simulate it? Cannot you use

    box.getDialog().hide(okButton);

  3. #3
    Sencha User
    Join Date
    Dec 2011
    Posts
    19
    Vote Rating
    0
    listirer is on a distinguished road

      0  

    Default


    Thanks, It works!

Thread Participants: 1