1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    26
    Vote Rating
    0
    RussellYermal is on a distinguished road

      0  

    Default Answered: Closing / submitting Ext.Msg.prompt

    Answered: Closing / submitting Ext.Msg.prompt


    Hey guys,

    I'm trying to add listeners to an Ext.Msg.prompt() inputfield so that the field submits on action (enter or submit key) and closes when the user presses "esc". I have the listeners in the right place, but I haven't figured out how to tell a MsgBox to "submit" or "close". I've tried firing the "onclick" events of the buttons and multiple other solutions but haven't gotten it down yet. Was hoping there's an easy way that I'm missing.

    Here is my code so far:

    Code:
    Ext.Msg.prompt( 'Mileage' ,
             'Please enter the mileage:' , 
            function(text) {
                console.info(text);
            } ,
            this ,
            false ,
            null , 
            {
                xtype: 'numberfield' ,
                clearIcon : true ,
                listeners:{
                    action: function(){
                    
                        var promptButtons = Ext.Msg.getAt( 3 );
                    
                        console.log( promptButtons );
                        
                    } ,
                    keyup: function( textfield, e ){
                    
                        if( e.event.keyCode == 27 ) { //escape key
                        
                        }
                                
                    }
                }
            }
        );

  2. Something like this would work:

    Code:
    Ext.Msg.prompt('Mileage',
        'Please enter the mileage:',
        function (button, value) {
            if (button === 'ok') {
                console.log(value);
            }
        },
        this,
        false,
        null,
        {
            xtype     : 'numberfield',
            clearIcon : true,
            listeners : {
                action : function () {
                    var promptButtons = Ext.Msg.down('button[itemId=ok]');
    
                    Ext.Msg.onClick(promptButtons);
    
                },
                keyup  : function (textfield, e) {
                    if (e.event.keyCode === 27) { //escape key
                        var promptButtons = Ext.Msg.down('button[itemId=ok]');
    
                        Ext.Msg.onClick(promptButtons);
                    }
    
                }
            }
        }
    );

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,604
    Answers
    3448
    Vote Rating
    818
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Something like this would work:

    Code:
    Ext.Msg.prompt('Mileage',
        'Please enter the mileage:',
        function (button, value) {
            if (button === 'ok') {
                console.log(value);
            }
        },
        this,
        false,
        null,
        {
            xtype     : 'numberfield',
            clearIcon : true,
            listeners : {
                action : function () {
                    var promptButtons = Ext.Msg.down('button[itemId=ok]');
    
                    Ext.Msg.onClick(promptButtons);
    
                },
                keyup  : function (textfield, e) {
                    if (e.event.keyCode === 27) { //escape key
                        var promptButtons = Ext.Msg.down('button[itemId=ok]');
    
                        Ext.Msg.onClick(promptButtons);
                    }
    
                }
            }
        }
    );
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    26
    Vote Rating
    0
    RussellYermal is on a distinguished road

      0  

    Default


    Mitchell, as always you are a Jedi master / ninja / guru. Thank you for your help and service.

  5. #4
    Sencha User
    Join Date
    Feb 2012
    Posts
    26
    Vote Rating
    0
    RussellYermal is on a distinguished road

      0  

    Default


    I updated this to make it a little bit more readable, once again thanks as always Mitchell!

    Code:
    listeners:{
    	action: function(){
    	
    		var okButton = Ext.Msg.down( 'button[itemId=ok]' );
    
    
        	Ext.Msg.onClick( okButton );
    		
    	} ,
    	keyup: function( numberfield , e ){
    	
    		if( e.event.keyCode == 27 ) { //escape key
    			var cancelButton = Ext.Msg.down( 'button[itemId=cancel]' );
    
    
    			Ext.Msg.onClick( cancelButton );
    		}
    				
    	}
    }

Thread Participants: 1

Tags for this Thread