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

      0  

    Default Numberfield Prompt

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,220
    Vote Rating
    859
    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


    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 @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.

  3. #3
    Sencha User
    Join Date
    Jan 2012
    Posts
    12
    Vote Rating
    1
    a7xntho is on a distinguished road

      1  

    Default Incorrect parameter !

    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);
    });