* @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)
*/
* @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
*/
thousandsDelimiter : false,
-
+ /**
+ * @cfg {Number} max_length Maximum input field length allowed (defaults to Number.MAX_VALUE)
+ */
+ max_length: false,
inputlg : 9,
inputmd : 9,
cls: 'hidden-number-input'
};
+ if(this.max_length) {
+ input.maxlength = this.max_length;
+ }
+
if (this.name) {
hiddenInput.name = this.name;
}
hiddenInput
];
- Roo.log(cfg);
-
var settings = this;
['xs','sm','md','lg'].map(function(size){
allowed += "-";
}
+ if(this.thousandsDelimiter) {
+ allowed += ",";
+ }
+
this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
var keyPress = function(e){
setValue : function(v)
{
- v = this.fixPrecision(v);
-
- v = String(v).replace(".", this.decimalSeparator);
+ v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
this.value = v;
this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
- this.inputEl().dom.value = Roo.util.Format.number(v, this.decimalPrecision,
- this.thousandsDelimiter || ','
- );
+ this.inputEl().dom.value = (v == '') ? '' :
+ Roo.util.Format.number(v, this.decimalPrecision, this.thousandsDelimiter || '');
- if(this.allowBlank && !v) {
+ if(!this.allowZero && v === '0') {
+ this.hiddenEl().dom.value = '';
this.inputEl().dom.value = '';
}
getRawValue : function()
{
- var v = this.hiddenEl().getValue();
+ var v = this.inputEl().getValue();
return v;
},
parseValue : function(value)
{
+ if(this.thousandsDelimiter) {
+ value += "";
+ r = new RegExp(",", "g");
+ value = value.replace(r, "");
+ }
+
value = parseFloat(String(value).replace(this.decimalSeparator, "."));
return isNaN(value) ? '' : value;
+
},
fixPrecision : function(value)
{
+ if(this.thousandsDelimiter) {
+ value += "";
+ r = new RegExp(",", "g");
+ value = value.replace(r, "");
+ }
+
var nan = isNaN(value);
if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
return nan ? '' : value;
}
-
return parseFloat(value).toFixed(this.decimalPrecision);
},
var v = this.parseValue(this.getRawValue());
- if(v){
+ if(v || v == 0){
this.setValue(v);
}
},