Results 1 to 3 of 3

Thread: Numberfield Prompt

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

    Default Numberfield Prompt

    Hey guys,

    I needed a prompt for a numberfield instead of text so I extended Ext.MessageBox, here it is if you need it!
    Code:
    Ext.define( 'App.NumberPrompt' , {
        extend: "Ext.MessageBox" ,
        requires: [
            'Ext.field.Number'
        ],
        xtype: "numberPrompt" ,
        applyPrompt: function(prompt) {
            if (prompt) {
                var config = {
                    label: false
                };
    
    
                if (Ext.isObject(prompt)) {
                    Ext.apply(config, prompt);
                }
    
    
                return Ext.factory(config, Ext.field.Number, this.getPrompt());
            }
    
    
            return prompt;
        } 
    });
    Usage:

    Code:
    var myNumberPrompt = Ext.create( 'App.NumberPrompt' );
        
        myNumberPrompt.prompt( 'Number' , 
                        'Please enter a number:' , 
                        function( number ) {
                            // process number value and close...
                        });

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,551
    Vote Rating
    1271
      0  

    Default

    Your code produces a number field. One thing I would do is applyPrompt as two arguments, the new prompt and the current prompt

    Code:
        applyPrompt : function (prompt, oldPrompt) {
            if (prompt) {
                var config = {
                    label : false
                };
    
                if (Ext.isObject(prompt)) {
                    Ext.apply(config, prompt);
                }
    
                return Ext.factory(config, Ext.field.Number, oldPrompt);
            }
    
            return prompt;
        }
    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

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    12
    Vote Rating
    1
      1  

    Default Incorrect parameter !

    When you use this number prompt, the number entered is THE SECOND paramater of the function
    In fact, the first paramater always return button status ('ok' or 'cancel')

    Code:
    myNumberPrompt.prompt( "Prompt",  'Enter a number :' , 
    function( a,number ) {
         console.log(number);
    });

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
  •