Roo/bootstrap/ComboBox.js
[roojs1] / roojs-bootstrap-debug.js
index 718e10b..0be573d 100644 (file)
@@ -7967,10 +7967,13 @@ clientValidation  Boolean          Applies to submit only.  Pass true to call fo
         var items = this.getItems();
         var ret = {};
         items.each(function(f){
+            
             if (!f.getName()) {
                 return;
             }
+            
             var v = f.getValue();
+            
             if (f.inputType =='radio') {
                 if (typeof(ret[f.getName()]) == 'undefined') {
                     ret[f.getName()] = ''; // empty..
@@ -7983,6 +7986,10 @@ clientValidation  Boolean          Applies to submit only.  Pass true to call fo
                 v = f.el.dom.value;
 
             }
+            
+            if(f.xtype == 'MoneyField'){
+                ret[f.currencyName] = f.getCurrency();
+            }
 
             // not sure if this supported any more..
             if ((typeof(v) == 'object') && f.getRawValue) {
@@ -14074,6 +14081,7 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
                     
                     this.onLoad();
                     
+                    Roo.log('onload???');
                     
                 }else{
                     
@@ -39998,6 +40006,8 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
     
     initEvents : function()
     {
+        this.indicator = this.indicatorEl();
+        
         this.initCurrencyEvent();
         
         this.initNumberEvent();
@@ -40015,16 +40025,10 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         
         this.createList();
         
-        this.indicator = this.indicatorEl();
-        
         this.triggerEl = this.el.select('.input-group-addon', true).first();
         
         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(){
@@ -40050,7 +40054,7 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         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();
@@ -40101,10 +40105,52 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
             forceKeyDown: true
         });
         
+        this.queryDelay = Math.max(this.queryDelay || 10,
+                this.mode == 'local' ? 10 : 250);
+        
+        
+        this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
+        
+        if(this.typeAhead){
+            this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
+        }
+        
+        this.currencyEl().on("keyup", this.onCurrencyKeyUp, this);
+        
     },
     
     initNumberEvent : function(e)
     {
+        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);
+        
+        if(this.indicator){
+            this.indicator.addClass('invisible');
+        }
+        this.originalValue = this.getValue();
+        
+        if(this.validationEvent == 'keyup'){
+            this.validationTask = new Roo.util.DelayedTask(this.validate, this);
+            this.inputEl().on('keyup', this.filterValidation, this);
+        }
+        else if(this.validationEvent !== false){
+            this.inputEl().on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
+        }
+        
+        if(this.selectOnFocus){
+            this.on("focus", this.preFocus, this);
+            
+        }
+        if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
+            this.inputEl().on("keypress", this.filterKeys, this);
+        } else {
+            this.inputEl().relayEvent('keypress', this);
+        }
+        
         var allowed = "0123456789";
         
         if(this.allowDecimals){
@@ -40140,7 +40186,7 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
             }
         };
         
-        this.amountEl.on("keypress", keyPress, this);
+        this.inputEl().on("keypress", keyPress, this);
         
     },
     
@@ -40170,15 +40216,15 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
     
     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)
@@ -40210,10 +40256,10 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         
         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;
@@ -40223,7 +40269,11 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
     
     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 = '';
         
@@ -40242,7 +40292,7 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         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();
         }
     },
@@ -40256,14 +40306,14 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         this.value = v;
         
         if(this.rendered){
-            this.amountEl.dom.value = (v === null || v === undefined ? '' : v);
+            this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
             this.validate();
         }
     },
     
     getRawValue : function()
     {
-        var v = this.amountEl.getValue();
+        var v = this.inputEl().getValue();
         
         return v;
     },
@@ -40337,6 +40387,107 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         
         this.markInvalid();
         return false;
+    },
+    
+    getName: function()
+    {
+        return this.name;
+    },
+    
+    beforeBlur : function()
+    {
+        if(!this.castInt){
+            return;
+        }
+        
+        var v = this.parseValue(this.getRawValue());
+        
+        if(v){
+            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);
+    },
+    
+    onCurrencyKeyUp : function(e)
+    {
+        Roo.log('on currency keyup');
+        if(!e.isSpecialKey()){
+            this.lastKey = e.getKey();
+            this.dqTask.delay(this.queryDelay);
+        }
+    },
+    
+    inputEl : function()
+    {
+        return this.el.select('.roo-money-amount-input', true).first();
+    },
+    
+    currencyEl : function()
+    {
+        return this.el.select('.roo-money-currency-input', true).first();
+    },
+    
+    initQuery : function()
+    {
+        var v = this.getCurrency();
+        Roo.log('initQuery???');
+        this.doQuery(v);
+    },
+    
+    onTypeAhead : function()
+    {
+        if(this.store.getCount() > 0){
+            var r = this.store.getAt(0);
+            var newValue = r.data[this.currencyField];
+            var len = newValue.length;
+            var selStart = this.getCurrency().length;
+            
+            if(selStart != len){
+                this.setCurrency(newValue);
+                this.selectText(selStart, newValue.length);
+            }
+        }
+    },
+    
+    selectText : function(start, end)
+    {
+        var v = this.getCurrency();
+        
+        if(v.length > 0){
+            start = start === undefined ? 0 : start;
+            end = end === undefined ? v.length : end;
+            var d = this.el.dom;
+            if(d.setSelectionRange){
+                d.setSelectionRange(start, end);
+            }else if(d.createTextRange){
+                var range = d.createTextRange();
+                range.moveStart("character", start);
+                range.moveEnd("character", v.length-end);
+                range.select();
+            }
+        }
     }
     
 });
\ No newline at end of file