Results 1 to 4 of 4

Thread: Closing / submitting Ext.Msg.prompt

  1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    26
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,553
    Answers
    3931
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    26
    Vote Rating
    0
      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
      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 );
    		}
    				
    	}
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •