Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
+ /**
+ * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
+ */
+ decimalSeparator : ".",
+
inputlg : 9,
inputmd : 9,
inputsm : 9,
});
return cfg;
+
},
initEvents : function()
+ {
+ this.initCurrencyEvent();
+
+ this.initNumberEvent();
+
+ },
+
+ initCurrencyEvent : function()
{
if (!this.store) {
throw "can not find store for combo";
this.amountEl = this.el.select('.roo-money-amount-input', true).first();
+ var _this = this;
+
+ (function(){
+ var lw = _this.listWidth || Math.max(_this.inputEl().getWidth(), _this.minListWidth);
+ _this.list.setWidth(lw);
+ }).defer(100);
+
+ this.list.on('mouseover', this.onViewOver, this);
+ this.list.on('mousemove', this.onViewMove, this);
+ this.list.on('scroll', this.onViewScroll, this);
+
+ if(!this.tpl){
+ this.tpl = '<li><a href="#">{' + this.currencyField + '}</a></li>';
+ }
+
+ this.view = new Roo.View(this.list, this.tpl, {
+ singleSelect:true, store: this.store, selectedClass: this.selectedClass
+ });
+
+ this.view.on('click', this.onViewClick, this);
+
+ this.store.on('beforeload', this.onBeforeLoad, this);
+ this.store.on('load', this.onLoad, this);
+ this.store.on('loadexception', this.onLoadException, this);
+
+ this.keyNav = new Roo.KeyNav(this.currencyEl, {
+ "up" : function(e){
+ this.inKeyMode = true;
+ this.selectPrev();
+ },
+
+ "down" : function(e){
+ if(!this.isExpanded()){
+ this.onTriggerClick();
+ }else{
+ this.inKeyMode = true;
+ this.selectNext();
+ }
+ },
+
+ "enter" : function(e){
+ this.collapse();
+
+ if(this.fireEvent("specialkey", this, e)){
+ this.onViewClick(false);
+ }
+
+ return true;
+ },
+
+ "esc" : function(e){
+ this.collapse();
+ },
+
+ "tab" : function(e){
+ this.collapse();
+
+ if(this.fireEvent("specialkey", this, e)){
+ this.onViewClick(false);
+ }
+
+ return true;
+ },
+
+ scope : this,
+
+ doRelay : function(foo, bar, hname){
+ if(hname == 'down' || this.scope.isExpanded()){
+ return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
+ }
+ return true;
+ },
+
+ forceKeyDown: true
+ });
+
+ },
+
+ initNumberEvent : function(e)
+ {
+ var allowed = "0123456789";
+
+ if(this.allowDecimals){
+ allowed += this.decimalSeparator;
+ }
+
+ if(this.allowNegative){
+ allowed += "-";
+ }
+
+ this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
+
+ var keyPress = function(e){
+
+ var k = e.getKey();
+
+ var c = e.getCharCode();
+
+ if(
+ (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
+ allowed.indexOf(String.fromCharCode(c)) === -1
+ ){
+ e.stopEvent();
+ return;
+ }
+
+ if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
+ return;
+ }
+
+ if(allowed.indexOf(String.fromCharCode(c)) === -1){
+ e.stopEvent();
+ }
+ };
+
+ this.amountEl.on("keypress", keyPress, this);
+
},
onTriggerClick : function(e)
this.collapse();
return;
}
- Roo.log('run on trigger click');
+
+ this.hasFocus = true;
+
if(this.triggerAction == 'all') {
this.doQuery(this.allQuery, true);
return;
{
this.list.alignTo(this.currencyEl, this.listAlign);
this.list.alignTo(this.currencyEl, this.listAlign);
- }
+ },
+ onViewClick : function(view, doFocus, el, e)
+ {
+ var index = this.view.getSelectedIndexes()[0];
+
+ var r = this.store.getAt(index);
+
+ if(r){
+ this.onSelect(r, index);
+ }
+ },
+
+ setFromData : function(o)
+ {
+ var currency = '';
+
+ this.lastData = o;
+
+ if (this.currencyField) {
+ currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
+ } else {
+ Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
+ }
+
+ this.lastSelectionText = currency;
+ this.currencyValue = currency;
+
+ this.setCurrency(currency);
+
+
+ },
+
+ setCurrency : function(v)
+ {
+ this.currencyValue = v;
+
+ if(this.rendered){
+ this.currencyEl.dom.value = (v === null || v === undefined ? '' : v);
+ this.validate();
+ }
+ },
+
+ validate : function()
+ {
+ return;
+
+ var v = this.getRawValue();
+
+ if(this.multiple){
+ v = this.getValue();
+ }
+
+ if(this.disabled || this.allowBlank || v.length){
+ this.markValid();
+ return true;
+ }
+
+ this.markInvalid();
+ return false;
+ },
+
+ parseValue : function(value)
+ {
+ value = parseFloat(String(value).replace(this.decimalSeparator, "."));
+ return isNaN(value) ? '' : value;
+ },
+
+ fixPrecision : function(value)
+ {
+ var nan = isNaN(value);
+
+ if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
+ return nan ? '' : value;
+ }
+
+ return parseFloat(value).toFixed(this.decimalPrecision);
+ },
+
+ decimalPrecisionFcn : function(v)
+ {
+ return Math.floor(v);
+ },
+
+ setValue : function(v)
+ {
+ v = this.fixPrecision(v);
+ Roo.bootstrap.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
+ }
});
\ No newline at end of file