/**
* @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
*/
- decimalPrecision : 2,
+ decimalPrecision : 0,
/**
* @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)
*/
* value should be in lkey
*/
defaultCurrency : false,
+ /**
+ * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
+ */
+ thousandsDelimiter : false,
inputlg : 9,
autocomplete: 'new-password'
};
+ var hiddenInput = {
+ tag: 'input',
+ type: 'hidden',
+ id: Roo.id(),
+ cls: 'hidden-number-input'
+ };
+
+ if(
+ this.maxLength &&
+ Number.isInteger(this.maxLength * 1)
+ ) {
+ input.maxlength = this.maxLength;
+ }
+
if (this.name) {
- input.name = this.name;
+ hiddenInput.name = this.name;
}
if (this.disabled) {
cfg.cn = [
label,
- container
+ container,
+ hiddenInput
];
-
+
var settings = this;
['xs','sm','md','lg'].map(function(size){
});
return cfg;
-
},
initEvents : function()
this.initCurrencyEvent();
this.initNumberEvent();
-
},
initCurrencyEvent : function()
allowed += "-";
}
+ if(this.thousandsDelimiter) {
+ allowed += ",";
+ }
+
this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
var keyPress = function(e){
this.lastSelectionText = currency;
+ //setting default currency
if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
this.setCurrency(this.defaultCurrency);
+ return;
}
this.setCurrency(currency);
setValue : function(v)
{
- v = this.fixPrecision(v);
-
- v = String(v).replace(".", this.decimalSeparator);
+ v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
this.value = v;
if(this.rendered){
- this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
+
+ this.hiddenEl().dom.value = (v === null || v === undefined ? '' : 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();
}
},
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);
}
},
currencyEl : function()
{
return this.el.select('.roo-money-currency-input', true).first();
+ },
+
+ hiddenEl : function()
+ {
+ return this.el.select('input.hidden-number-input',true).first();
}
});
\ No newline at end of file