PDA

View Full Version : [2.0b1][SOLVED] setValue method does not check for invalid data (fix attached)



pluesch0r
15 Oct 2007, 12:17 AM
When using a Ext.form.NumberField in a form that loads data via JSON and the value for that NumberField is null, the setValue method in NumberField.js on line 117 sets the (invalid) value of null to display in that field.



setValue : function(v){
Ext.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
},

should be


setValue : function(v){
Ext.form.NumberField.superclass.setValue.call(this, this.parseValue(v));
},


Keep up the good work,
Martin

jack.slocum
15 Oct 2007, 3:24 AM
null is not a valid value for a NumberField. In javascript, typeof null == 'object', so a number can never be null.

However, I do see how this could be an common issue and the patch looks harmless enough. Thanks for posting.

pluesch0r
22 Oct 2007, 7:37 AM
Hi there,

unfortunately, the code I submitted earlier introduces a bug when submitting values that use a custom DecimalSeparator. The following code honors that case.


Ext.form.NumberField.prototype.setValue = function(v){
Ext.form.NumberField.superclass.setValue.call(this, String(parseFloat(v)).replace(".", this.decimalSeparator));
}

Sorry for the inconvenience.

jack.slocum
22 Oct 2007, 2:03 PM
No problem. That's for the update.