/*
* - LGPL
*
- * Input
- *
+ * Number field
*/
/**
* @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
*/
allowNegative : true,
+
+ /**
+ * @cfg {Boolean} allowZero False to blank out if the user enters '0' (defaults to true)
+ */
+ allowZero: true,
/**
* @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
*/
* if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
*/
nanText : "{0} is not a valid number",
- /**
- * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
- */
- castInt : true,
- /**
- * @cfg {Boolean} allowThousandsDelimiter (true|false) display thousands delimiter if true (e.g. "100,000") (defalut false)
- */
- allowThousandsDelimiter : false,
/**
* @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
*/
- thousandsDelimiter : ",",
+ thousandsDelimiter : false,
/**
* @cfg {String} valueAlign alignment of value
*/
allowed += "-";
}
- if(this.allowThousandsDelimiter) {
- allowed += this.thousandsDelimiter;
+ if(this.thousandsDelimiter) {
+ allowed += ",";
}
this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
parseValue : function(value)
{
- if(this.allowThousandsDelimiter) {
+ if(this.thousandsDelimiter) {
value += "";
- r = new RegExp(this.thousandsDelimiter, "g");
+ r = new RegExp(",", "g");
value = value.replace(r, "");
}
fixPrecision : function(value)
{
- if(this.allowThousandsDelimiter) {
+ if(this.thousandsDelimiter) {
value += "";
- r = new RegExp(this.thousandsDelimiter, "g");
+ r = new RegExp(",", "g");
value = value.replace(r, "");
}
this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
- this.inputEl().dom.value = (this.allowThousandsDelimiter ? this.addThousandsDelimiter(v) : v);
+ this.inputEl().dom.value = (v == '') ? '' :
+ Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
+
+ if(!this.allowZero && v === '0') {
+ this.hiddenEl().dom.value = '';
+ this.inputEl().dom.value = '';
+ }
this.validate();
}
beforeBlur : function()
{
- if(!this.castInt){
- return;
- }
-
var v = this.parseValue(this.getRawValue());
- if(v){
- this.setValue(v);
- }
- },
-
- addThousandsDelimiter : function(v)
- {
- if(!this.allowThousandsDelimiter) {
- return v;
- }
-
- v += "";
- var x = v.split(".");
-
- var x1 = x[0];
-
- var x2 = x.length > 1 ? "." + x[1] : "";
-
- var rgx = /(\d+)(\d{3})/;
-
- while (rgx.test(x1)) {
- x1 = x1.replace(rgx, "$1" + this.thousandsDelimiter + "$2");
+ if(v || v === 0 || v === ''){
+ this.setValue(v);
}
-
- return x1 + x2;
},
hiddenEl : function()