/**
* @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)
*/
* @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
*/
castInt : true,
+ /**
+ * @cfg {String} defaults currency of the MoneyField
+ * value should be in lkey
+ */
+ defaultCurrency : false,
+ /**
+ * @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,
autocomplete: 'new-password'
};
+ var hiddenInput = {
+ tag: 'input',
+ type: 'hidden',
+ id: Roo.id(),
+ cls: 'hidden-number-input'
+ };
+
+ if(this.max_length) {
+ input.maxlength = this.max_length;
+ }
+
if (this.name) {
- input.name = this.name;
+ hiddenInput.name = this.name;
}
if (this.disabled) {
{
tag : 'input',
cls : 'form-control roo-money-currency-input',
- autocomplete: 'new-password'
+ autocomplete: 'new-password',
+ readOnly : 1,
+ name : this.currencyName
},
{
tag :'span',
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()
this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
- this.currencyEl = this.el.select('.roo-money-currency-input', true).first();
-
- this.amountEl = this.el.select('.roo-money-amount-input', true).first();
-
var _this = this;
(function(){
this.store.on('load', this.onLoad, this);
this.store.on('loadexception', this.onLoadException, this);
- this.keyNav = new Roo.KeyNav(this.currencyEl, {
+ this.keyNav = new Roo.KeyNav(this.currencyEl(), {
"up" : function(e){
this.inKeyMode = true;
this.selectPrev();
forceKeyDown: true
});
+ this.currencyEl().on("click", this.onTriggerClick, this, { preventDefault : true });
+
},
initNumberEvent : function(e)
{
- this.amountEl.on("keydown" , this.fireKey, this);
- this.amountEl.on("focus", this.onFocus, this);
- this.amountEl.on("blur", this.onBlur, this);
+ this.inputEl().on("keydown" , this.fireKey, this);
+ this.inputEl().on("focus", this.onFocus, this);
+ this.inputEl().on("blur", this.onBlur, this);
this.inputEl().relayEvent('keyup', this);
- this.indicator = this.indicatorEl();
-
if(this.indicator){
this.indicator.addClass('invisible');
-
}
- // reference to original value for reset
this.originalValue = this.getValue();
- //Roo.form.TextField.superclass.initEvents.call(this);
+
if(this.validationEvent == 'keyup'){
this.validationTask = new Roo.util.DelayedTask(this.validate, this);
this.inputEl().on('keyup', this.filterValidation, this);
} else {
this.inputEl().relayEvent('keypress', this);
}
- /* if(this.grow){
- this.el.on("keyup", this.onKeyUp, this, {buffer:50});
- this.el.on("click", this.autoSize, this);
- }
- */
- if(this.inputEl().is('input[type=password]') && Roo.isSafari){
- this.inputEl().on('keydown', this.SafariOnKeyDown, this);
- }
-
- if (typeof(this.before) == 'object') {
- this.before.render(this.el.select('.roo-input-before',true).first());
- }
- if (typeof(this.after) == 'object') {
- this.after.render(this.el.select('.roo-input-after',true).first());
- }
var allowed = "0123456789";
allowed += "-";
}
+ if(this.thousandsDelimiter) {
+ allowed += ",";
+ }
+
this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
var keyPress = function(e){
}
};
- this.amountEl.on("keypress", keyPress, this);
+ this.inputEl().on("keypress", keyPress, this);
},
getCurrency : function()
{
- var v = this.currencyEl.getValue();
+ var v = this.currencyEl().getValue();
return v;
},
restrictHeight : function()
{
- this.list.alignTo(this.currencyEl, this.listAlign);
- this.list.alignTo(this.currencyEl, this.listAlign);
+ this.list.alignTo(this.currencyEl(), this.listAlign);
+ this.list.alignTo(this.currencyEl(), this.listAlign);
},
onViewClick : function(view, doFocus, el, e)
this.lastCurrency = o;
- if (this.currencyName) {
- currency = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
+ if (this.currencyField) {
+ currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
} else {
- Roo.log('no currencyName value set for '+ (this.name ? this.name : this.id));
+ Roo.log('no currencyField value set for '+ (this.name ? this.name : this.id));
}
this.lastSelectionText = currency;
+ //setting default currency
+ if(o[this.currencyField] * 1 == 0 && this.defaultCurrency) {
+ this.setCurrency(this.defaultCurrency);
+ return;
+ }
+
this.setCurrency(currency);
},
setFromData : function(o)
{
- this.setFromCurrencyData(o);
+ var c = {};
+
+ c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
+
+ this.setFromCurrencyData(c);
var value = '';
this.currencyValue = v;
if(this.rendered){
- this.currencyEl.dom.value = (v === null || v === undefined ? '' : v);
+ this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
this.validate();
}
},
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.amountEl.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();
}
},
getRawValue : function()
{
- var v = this.amountEl.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);
},
validate : function()
{
- if(this.disabled){
+ if(this.disabled || this.allowBlank){
this.markValid();
return true;
}
return this.name;
},
+ beforeBlur : function()
+ {
+ if(!this.castInt){
+ return;
+ }
+
+ var v = this.parseValue(this.getRawValue());
+
+ if(v || v == 0){
+ this.setValue(v);
+ }
+ },
+
onBlur : function()
{
this.beforeBlur();
+
if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
//this.el.removeClass(this.focusClass);
}
+
this.hasFocus = false;
+
if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
this.validate();
}
+
var v = this.getValue();
+
if(String(v) !== String(this.startValue)){
this.fireEvent('change', this, v, this.startValue);
}
+
this.fireEvent("blur", this);
},
+ inputEl : function()
+ {
+ return this.el.select('.roo-money-amount-input', true).first();
+ },
+
+ 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