1. #1
    Sencha Premium Member
    Join Date
    Jul 2007
    Posts
    117
    Answers
    1
    Vote Rating
    1
    borg is on a distinguished road

      0  

    Default Unanswered: Why does numberfield ignore decimalPrecision?

    Unanswered: Why does numberfield ignore decimalPrecision?


    Why do I have to override the numberfield to make decimal precision work? Is it a bug? Seems broken to me.

    Code:
    xtype: 'numberfield',
    forcePrecision: true,	// custom for override, otherwise behaves as default
    decimalPrecision: 2
    
    
    	Ext.override(Ext.form.NumberField, {
    		forcePrecision : false,
    
    		valueToRaw: function(value) {
    			var me = this, decimalSeparator = me.decimalSeparator;
    			value = me.parseValue(value);
    			value = me.fixPrecision(value);
    			value = Ext.isNumber(value) ? value : parseFloat(String(value).replace(decimalSeparator, '.'));
    			if (isNaN(value)) {
    				value = '';
    			}
    			else {
    				value = me.forcePrecision ? value.toFixed(me.decimalPrecision) : parseFloat(value);
    				value = String(value).replace(".", decimalSeparator);
    			}
    			return value;
    		}
    	});
    Ext-4.2.1 / Windows 7 SP1 / Firefox 24 / Firebug 1.12.2

  2. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    5,470
    Answers
    442
    Vote Rating
    202
    slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of

      0  

    Default


    The following code from the 4.2 API examples seems to work ok for me. I enter 23.454 and blur the field and I get 23.45. I enter 23.399 and I get 23.4 since the decimalPrecision defaults to 2. What are you seeing?

    Code:
    Ext.create('Ext.form.Panel', {
        title: 'Personal Info',
        width: 300,
        bodyPadding: 10,
        renderTo: Ext.getBody(),
        items: [{
            xtype: 'numberfield',
            anchor: '100%',
            name: 'age',
            fieldLabel: 'Age',
            minValue: 0, //prevents negative numbers
    
    
            // Remove spinner buttons, and arrow key and mouse wheel listeners
            hideTrigger: true,
            keyNavEnabled: false,
            mouseWheelEnabled: false
        }]
    });

  3. #3
    Sencha Premium Member
    Join Date
    Jul 2007
    Posts
    117
    Answers
    1
    Vote Rating
    1
    borg is on a distinguished road

      0  

    Default


    The issue seems to be that the default behavior of this config param is unexpected. If you have a number like 240.30 it will only show 240.3 If you have 240 it will only show 240. It should be showing 240.30 and 240.00 respectively. I suggest changing the way the config param operates or adding a forcePrecision config option. What do you think?
    Ext-4.2.1 / Windows 7 SP1 / Firefox 24 / Firebug 1.12.2

Thread Participants: 1