1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Boston
    Posts
    141
    Answers
    5
    Vote Rating
    6
    drb is on a distinguished road

      0  

    Default Answered: How to I prevent an Ext.MessageBox Button closing the MessageBox?

    Answered: How to I prevent an Ext.MessageBox Button closing the MessageBox?


    I want to put a button on a MessageBox that does not close the box when it is tapped.
    Other buttons on the box will close the box, but not this one.

  2. Thank you Jerome.

    I did an override for onClick. I'm not sure dontHide is a good name for the new button property (see italics below), but it works.

    Code:
            Ext.define('Ext.overrides.MessageBox', {
                // Support dontHide configuration property for Button
                override: 'Ext.MessageBox',
                onClick: function (button) {
                    if (button) {
                        var config = button.config.userConfig || {},
                        initialConfig = button.getInitialConfig(),
                        prompt = this.getPrompt();
    
                        if (typeof config.fn == 'function') {
                            this.on({
                                hiddenchange: function () {
                                    config.fn.call(
                                    config.scope || null,
                                    initialConfig.itemId || initialConfig.text,
                                    prompt ? prompt.getValue() : null,
                                    config
                                );
                                },
                                single: true,
                                scope: this
                            });
                        }
    
                        if (config.input) {
                            config.input.dom.blur();
                        }
                    }
    
                    if (!initialConfig.dontHide) {
                        this.hide();
                    }
                }
    
            });

  3. #2
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132
    Vote Rating
    99
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    If you take a look at the source of Ext.MessageBox, you can search for the onClick function. Notice how it calls this.hide(). You can create your own Ext.Msg that fires a different event which doesn't hide the object, or you can override Sencha's current onClick function to perform a check that if it is your custom button then to not hide the object.

    You can see in the show function, they set the handler of each button to fire this 'onClick' event:
    Code:
     buttonBarItems.push(Ext.apply({
                    userConfig: userConfig,
                    scope     : this,
                    handler   : 'onClick'
                 }, buttonConfig));
    I hope this helps you out

  4. #3
    Sencha User
    Join Date
    Sep 2011
    Location
    Boston
    Posts
    141
    Answers
    5
    Vote Rating
    6
    drb is on a distinguished road

      0  

    Default


    Thank you Jerome.

    I did an override for onClick. I'm not sure dontHide is a good name for the new button property (see italics below), but it works.

    Code:
            Ext.define('Ext.overrides.MessageBox', {
                // Support dontHide configuration property for Button
                override: 'Ext.MessageBox',
                onClick: function (button) {
                    if (button) {
                        var config = button.config.userConfig || {},
                        initialConfig = button.getInitialConfig(),
                        prompt = this.getPrompt();
    
                        if (typeof config.fn == 'function') {
                            this.on({
                                hiddenchange: function () {
                                    config.fn.call(
                                    config.scope || null,
                                    initialConfig.itemId || initialConfig.text,
                                    prompt ? prompt.getValue() : null,
                                    config
                                );
                                },
                                single: true,
                                scope: this
                            });
                        }
    
                        if (config.input) {
                            config.input.dom.blur();
                        }
                    }
    
                    if (!initialConfig.dontHide) {
                        this.hide();
                    }
                }
    
            });

  5. #4
    Sencha User jerome76's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,149
    Answers
    132
    Vote Rating
    99
    jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice jerome76 is just really nice

      0  

    Default


    Oh wonderful! I will save this for future reference

Thread Participants: 1

Tags for this Thread