PDA

View Full Version : NumberField setValue does not shows value when using custom decimalSeparator



gianmarco
2 Feb 2011, 3:34 AM
Ext version: 3.3.1

The following repro code is quite clear:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="extjs/adapter/ext/ext-base-debug.js"></script>
<script type="text/javascript" src="extjs/ext-all-debug-w-comments.js"></script>
<script type="text/javascript">
"use strict";

Ext.onReady(function () {
var numberField1 = new Ext.form.NumberField({decimalSeparator: ','});
numberField1.setValue(1.4);
var numberField2 = new Ext.form.NumberField();
numberField2.setValue(1.4);
var viewPort = new Ext.Viewport({
layout: 'form',
items:[numberField1, numberField2]
});
});
</script>
<title></title>
</head>
<body>
</body>
</html>

Xam335
2 Feb 2011, 4:31 AM
My small help:
It works in the 3.2.1. The fixPrecision method is the problem here. It does not recognize the value as a number because of the different decimal separator and so return an empty value back to setValue.

(I am still unclear for me why go through this setValue method so often for one render.)

Condor
2 Feb 2011, 4:45 AM
Not seeing this problem in the current ext 3.3+ branch, so it's probably already fixed.

gianmarco
2 Feb 2011, 5:04 AM
I've patched Ext.form.NumberField following this post (http://www.sencha.com/forum/showthread.php?117022). PatchedNumberField work as expected:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="extjs/adapter/ext/ext-base-debug.js"></script>
<script type="text/javascript" src="extjs/ext-all-debug-w-comments.js"></script>
<script type="text/javascript">
"use strict";

Ext.form.PatchedNumberField = Ext.extend(Ext.form.NumberField, {
setValue : function(v) {
v = Ext.isNumber(v) ? v : parseFloat(String(v).replace(this.decimalSeparator, "."));
return Ext.form.PatchedNumberField.superclass.setValue.call(this, v);
}
});
Ext.reg('Ext.form.PatchedNumberField', Ext.form.PatchedNumberField);

Ext.onReady(function () {
var numberField1 = new Ext.form.NumberField({id:'numberField1', decimalSeparator: ','});
numberField1.setValue(1.4);
var numberField2 = new Ext.form.NumberField({id:'numberField2'});
numberField2.setValue(1.4);
var numberField3 = new Ext.form.PatchedNumberField({id:'numberField3', decimalSeparator: ','});
numberField3.setValue(1.4);
var viewPort = new Ext.Viewport({
layout: 'form',
items:[numberField1, numberField2, numberField3]
});
});
</script>
<title></title>
</head>
<body>
</body>
</html>

gianmarco
2 Feb 2011, 5:08 AM
Not seeing this problem in the current ext 3.3+ branch, so it's probably already fixed.
Yes, as i wrote in the previous post, i think

http://www.sencha.com/forum/showthread.php?117022

fix the problem. Hope to have this patch in 3.3.2