[CLOSED] Ext.Msg.Confirm Key Binding?

  1. #1

    [CLOSED] Ext.Msg.Confirm Key Binding?

    Just a quick one. I search Sencha API and Forum but found nothing.

    How to catch the "ESC" Key pressed on confirm or any Msg?

    Ext.Msg.confirm('Test','Some Question?', function (btn) {
                        if (btn == 'yes') {                     
                          alert('yes');
                        }else{ 
                          alert('not yes');
                        }
                    });
    If I click Yes,No I get into the callback, but on ESC Key it just closes.
    Last edited by Daniil; Nov 22, 2010 at 9:20 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Please look at the example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
        <ext:ResourcePlaceHolder runat="server" />
    
        <script type="text/javascript">
            Ext.onReady(function() {
                var dlg = Ext.Msg.getDialog();
                dlg.getKeyMap().bindings.pop(); //removing default Esc handler
    
                var escHandler = function(k, e) {
                    if (confirm("Exit?")) {
                        this.onEsc(k, e);
                    }
                }
    
                dlg.getKeyMap().on(27, escHandler, dlg);
                Ext.Msg.alert("Test", "Press Esc...");
            });
            
        </script>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        </form>
    </body>
    </html>
  3. #3
    Quote Originally Posted by csharpdev View Post
    ...If I click Yes,No I get into the callback, but on ESC Key it just closes.
    The ESC key should be triggering the callback and passing the id of 'no'. I just tested on Ext JS 3.3 and it works as expected. The documentation state this behavior as well.

    the id of the button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
    Daniil's solution would make it so the same handler is called for all Ext.Msg's when the ESC key is pressed. Probably not what you really want to do.

    Check to see what version you have and either upgrade or use and Override to fix the problem. Thats my suggestion at least.
  4. #4
    Quote Originally Posted by VinylFox View Post
    The ESC key should be triggering the callback I just tested on Ext JS 3.3 and it works as expected. The documentation state this behavior as well.
    Oh, you are right. I forgot about it, didn't tested the code @csharpdev posted and immediately began to find another solution:)

    @csharpdev, I see wrong arguments in your code. The second one must be message, the third one must be a callback function.

    As VinylFox mentioned the ESC key should be triggering the callback. I tested this too.

    VinylFox, but I can't see this in documentation. Where is this?

    I see only
    A callback function which is called when the dialog is dismissed either by clicking on the configured buttons, or on the dialog close button, or by pressing the return button to enter input.
    Quote Originally Posted by VinylFox View Post
    Daniil's solution would make it so the same handler is called for all Ext.Msg's when the ESC key is pressed. Probably not what you really want to do.
    It was just a rough demonstration of another way to achieve the requirement. It can be improved to call different handlers with each calling Ext.Msg's "showing" methods. But it was work for nothing. Maybe, not. At least it demonstrates how to override default Esc behavior:)

    Thank you again for the clarification.
  5. #5
    Hi,

    The problem: all windows under Ext.Net have CloseAction="Hide" by default therefore callback is not triggered when you press Esc or close button

    Fixed in SVN. Please update
  6. #6
    Thanks, with latest SVN it works now. Pls mark as solved.

    @Daniil: updated wrong confirm() call in first msg.
  7. #7
    Quote Originally Posted by csharpdev View Post
    @Daniil: updated wrong confirm() call in first msg.
    Thank you for the feedback.

Similar Threads

  1. [CLOSED] Ext.Msg.Confirm vs Confirm with DirectEvents
    By csharpdev in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 21, 2013, 10:51 AM
  2. Replies: 2
    Last Post: Jul 10, 2012, 8:09 PM
  3. [CLOSED] Ext.Msg.Confirm
    By majestic in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Feb 14, 2012, 6:11 PM
  4. [CLOSED] Confirm Box
    By sharif in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 16, 2010, 11:21 AM
  5. [CLOSED] Confirm MessageBox
    By gokcemutlu in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: May 13, 2009, 12:47 PM

Tags for this Thread

Posting Permissions