1. #21
    Sencha User
    Join Date
    Sep 2010
    Posts
    1
    Vote Rating
    0
    howgoo is on a distinguished road

      0  

    Default


    Quote Originally Posted by mysticav View Post
    Very disappointed to find that it does not support format for decimals.

    I'm looking for an spreadsheet field behavior, where I can define a format decimal precision and the real decimal precision.

    Example:
    For the real value I would enter: 33.33333333
    The displayed value would be: $ 33.33

    but then, the raw value will still be: 33.3333333

    This class doesn't keep the real value.

    So I hope the creator improves it, or somebody collaborate with that functionality.

    Thanks.
    extjs333333333.jpg

    When I enter the value 33.33333333,The results were not what you(@mysticav) said that.
    I user #14 @pmiguelmartins 's code.

  2. #22
    Sencha User
    Join Date
    Jun 2007
    Posts
    125
    Vote Rating
    1
    bhaidaya is on a distinguished road

      0  

    Default


    You might want to switch

    Code:
    value = value.toString().replace(this.currencySymbol + ' ', '');
    to

    Code:
    value = value.toString().replace(this.currencySymbol , '').trim();
    as to allow parsing the field value a bit better in the case the value is submitted as $2,000.00 (no space)

    edit: thanks!

  3. #23
    Sencha User
    Join Date
    Jun 2007
    Posts
    125
    Vote Rating
    1
    bhaidaya is on a distinguished road

      0  

    Default


    Is anyone else having the problem where you type 123 rapidly in the field and it ends up looking like this 1.0023.

    It seems that the field will autopad the decimals on first keydown but then leave the cursor at the end of the field resulting in the first button press + decimals + remaining button presses..

  4. #24
    Sencha User
    Join Date
    Jun 2007
    Posts
    125
    Vote Rating
    1
    bhaidaya is on a distinguished road

      0  

    Default


    Nevermind this seems to be a bug with 4.1

  5. #25
    Sencha User
    Join Date
    May 2014
    Posts
    1
    Vote Rating
    0
    tony.maroun is on a distinguished road

      0  

    Default


    It Works beautifully. Thanks

  6. #26
    Sencha User
    Join Date
    Jul 2014
    Posts
    2
    Vote Rating
    0
    phaiemko123 is on a distinguished road

      0  

    Default


    it does not work, anybody can help me. Thanks

  7. #27
    Sencha User
    Join Date
    Apr 2014
    Posts
    3
    Vote Rating
    0
    mkkguru is on a distinguished road

      0  

    Default


    Can you please let me know how to validate below type of validations in functions. var reqDependency20_1=((Ext.getCmp('i_7_2158_id') != undefined)?((((Ext.getCmp('i_7_559_id').getInputValueCT()+'') == '')&& ((Ext.getCmp('i_7_1846_id').getInputValueCT()+'') == '')&& ((Ext.getCmp('i_7_577_id').getInputValueCT()+'') == '')&&((Ext.getCmp('i_7_2158_id').getInputValueCT()+'') == '')&&((Ext.getCmp('i_7_2295_id').getInputValueCT()+'') == '')) ? true : (((Ext.getCmp('i_7_565_id').getInputValueCT()+'') != '') ? true (Ext.getCmp('i_80_1068_id').getInputValueCT()+'') == 'Audited')?true(Ext.getCmp('i_7_559_id').getInputValueCT()+'') == '')&& ((Ext.getCmp('i_7_565_id').getInputValueCT()+'') == '')&&((Ext.getCmp('i_7_1846_id').getInputValueCT()+'') == '')&&((Ext.getCmp('i_7_2158_id').getInputValueCT()+'') == '')&&((Ext.getCmp('i_7_2295_id').getInputValueCT()+'') == '')&& ((Ext.getCmp('i_7_577_id').getInputValueCT()+'') == '')))))((Ext.getCmp('i_7_559_id').getInputValueCT()+'') == '')&& ((Ext.getCmp('i_7_1846_id').getInputValueCT()+'') == '')&& ((Ext.getCmp('i_7_577_id').getInputValueCT()+'') == '')&&((Ext.getCmp('i_7_2295_id').getInputValueCT()+'') == '')) ? true : (((Ext.getCmp('i_7_565_id').getInputValueCT()+'') != '')? true (Ext.getCmp('i_80_1068_id').getInputValueCT()+'') == 'Audited')?true(Ext.getCmp('i_7_559_id').getInputValueCT()+'') == '')&& ((Ext.getCmp('i_7_565_id').getInputValueCT()+'') == '')&&((Ext.getCmp('i_7_1846_id').getInputValueCT()+'') == '')&&((Ext.getCmp('i_7_2295_id').getInputValueCT()+'') == '')&& ((Ext.getCmp('i_7_577_id').getInputValueCT()+'') == '')))))); Thanks in advance

  8. #28
    Touch Premium Member
    Join Date
    Mar 2011
    Posts
    120
    Vote Rating
    7
    chamacs is on a distinguished road

      0  

    Default


    Here is an updated version of the NumericField that is supported in ExtJS 5.0.1, along with various mods discussed in this thread and the 'Community Discussion' (http://www.sencha.com/forum/showthre...38#post1064138) thread.

    Code:
    /* * GNU General Public License Usage
     * This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
     *
     * http://www.gnu.org/licenses/lgpl.html
     *
     * @description: This class provide additional format to numbers by extending Ext.form.field.Number
     *
     * @author: Greivin Britton
     * @email: brittongr@gmail.com
     * @version: 2 compatible with ExtJS 4 (And ExtJS 5 - chamacs)
     */
    Ext.define('Ext.ux.form.NumericField', {
        extend: 'Ext.form.field.Number',//Extending the NumberField
        alias: 'widget.numericfield',//Defining the xtype
        
        currencySymbol: null,
        
        // MOD - chamacs
        // @private
        isCurrency : false,
        
        // MOD - pmiguelmartins
        currencySymbolPos : 'left', // left , right
        
        useThousandSeparator: true,
        thousandSeparator: ',',
        alwaysDisplayDecimals: false,
        // MOD - chamacs
        //fieldStyle: 'text-align: right;',
        
        // MOD - chamacs
        allowExponential : false,
        
        /**
         * initComponent
         */
        initComponent: function(){
            if (this.useThousandSeparator && this.decimalSeparator == ',' && this.thousandSeparator == ',') {
                this.thousandSeparator = '.';
            }
            else if (this.allowDecimals && this.thousandSeparator == '.' && this.decimalSeparator == '.') {
                this.decimalSeparator = ',';
            }
            
            // MOD - chamacs
            this.isCurrency = !Ext.isEmpty(this.currencySymbol);
            
            this.callParent(arguments);
        },
        
        /**
         * setValue
         */
        setValue: function(value){
            // MOD - chamacs
            Ext.ux.form.NumericField.superclass.setValue.apply(this, [value != null ? value.toString().replace('.', this.decimalSeparator) : value]);
            
            this.setRawValue(this.getFormattedValue(this.getValue()));
        },
        
        /**
         * getFormattedValue
         */
        getFormattedValue: function(value){
            if (Ext.isEmpty(value) || !this.hasFormat()) {
                return value;
            }
            else {
                var neg = null;
                
                value = (neg = value < 0) ? value * -1 : value;
                value = this.allowDecimals && this.alwaysDisplayDecimals ? value.toFixed(this.decimalPrecision) : value;
                
                if (this.useThousandSeparator) {
                    if (this.useThousandSeparator && Ext.isEmpty(this.thousandSeparator)) {
                        throw ('NumberFormatException: invalid thousandSeparator, property must has a valid character.');
                    }
                    if (this.thousandSeparator == this.decimalSeparator) {
                        throw ('NumberFormatException: invalid thousandSeparator, thousand separator must be different from decimalSeparator.');
                    }
                    
                    value = value.toString();
                    
                    var ps = value.split('.');
                    ps[1] = ps[1] ? ps[1] : null;
                    
                    var whole = ps[0];
                    
                    var r = /(\d+)(\d{3})/;
                    
                    var ts = this.thousandSeparator;
                    
                    while (r.test(whole)) {
                        whole = whole.replace(r, '$1' + ts + '$2');
                    }
                    
                    value = whole + (ps[1] ? this.decimalSeparator + ps[1] : '');
                }
                
                // MOD - pmiguelmartins - updated by chamacs
                var position1 = this.isCurrency ? this.currencySymbol + ' ' : '';
                var position2 = value;
                if (this.currencySymbolPos === 'right') {
                    position1 = value;
                    position2 = this.isCurrency ? ' ' + this.currencySymbol : '';
                }
                return Ext.String.format('{0}{1}{2}', (neg ? '-'  : ''), position1, position2);
            }
        },
        
        /**
         * overrides parseValue to remove the format applied by this class
         */
        parseValue: function(value){
            // MOD - chamacs
            //Replace the currency symbol and thousand separator
            return Ext.ux.form.NumericField.superclass.parseValue.apply(this, [this.removeFormat(value)]);
        },
        
        /**
         * Remove only the format added by this class to let the superclass validate with it's rules.
         * @param {Object} value
         */
        removeFormat: function(value){
            // MOD - chamacs
            if (Ext.isEmpty(value)) {
                return '';
            }
            else if (!this.hasFormat()) {
                return value;
            }
            else {
                // MOD - bhaidaya
                value = Ext.String.trim(value.toString().replace(this.currencySymbol, ''));
                
                value = this.useThousandSeparator ? value.replace(new RegExp('[' + this.thousandSeparator + ']', 'g'), '') : value;   
                return value;
            }
        },
        
        /**
         * Remove the format before validating the the value.
         * @param {Number} value
         */
        getErrors: function(value) {
            // MOD - chamacs
            return Ext.ux.form.NumericField.superclass.getErrors.apply(this, [this.removeFormat(value)]);
        },
        
        /**
         * hasFormat
         */
        hasFormat: function() {
            return this.decimalSeparator != '.' || (this.useThousandSeparator == true && this.getRawValue() != null) || !Ext.isEmpty(this.currencySymbol) || this.alwaysDisplayDecimals;
        },
        
        /**
         * Display the numeric value with the fixed decimal precision and without the format using the setRawValue, don't need to do a setValue because we don't want a double
         * formatting and process of the value because beforeBlur perform a getRawValue and then a setValue.
         */
        onFocus: function() {
            this.setRawValue(this.removeFormat(this.getRawValue()));
            
            this.callParent(arguments);
        },
        
        /**
         * MOD - Jeff.Evans
         */
        processRawValue: function(value) {
            return this.removeFormat(value);
        }
    });