/*
* - 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)
*/
*/
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)
+ * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
*/
- allowThousandsDelimiter : false,
+ thousandsDelimiter : false,
/**
- * @cfg {String} symbol of thousandsDelimiter
+ * @cfg {String} valueAlign alignment of value
*/
- thousandsDelimiter : ",",
+ valueAlign : "left",
getAutoCreate : function()
{
- var hidden_input_name = this.name;
+ var hiddenInput = {
+ tag: 'input',
+ type: 'hidden',
+ id: Roo.id(),
+ cls: 'hidden-number-input'
+ };
- Roo.log(this.name);
+ if (this.name) {
+ hiddenInput.name = this.name;
+ }
this.name = '';
var cfg = Roo.bootstrap.NumberField.superclass.getAutoCreate.call(this);
+ this.name = hiddenInput.name;
+
if(cfg.cn.length > 0) {
- cfg.cn.push({
- tag : 'input',
- id : id,
- name : hidden_input_name,
- value : this.value,
- type : 'hidden',
- cls: 'form-hidden-field'
- })
+ cfg.cn.push(hiddenInput);
}
- Roo.log(cfg);
-
return cfg;
},
allowed += "-";
}
+ if(this.thousandsDelimiter) {
+ allowed += ",";
+ }
+
this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
var keyPress = function(e){
getValue : function()
{
- return this.fixPrecision(this.parseValue(Roo.bootstrap.NumberField.superclass.getValue.call(this)));
+ var v = this.hiddenEl().getValue();
+
+ return this.fixPrecision(this.parseValue(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){
setValue : function(v)
{
- v = this.fixPrecision(v);
- Roo.bootstrap.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
+ v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
+
+ this.value = v;
+
+ if(this.rendered){
+
+ 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();
+ }
},
decimalPrecisionFcn : function(v)
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;
},
- inputEl: function ()
+ hiddenEl : function()
{
- return this.el.select('input.form-hidden-field',true).first();
+ return this.el.select('input.hidden-number-input',true).first();
}
});