Roo/bootstrap/ComboBox.js
[roojs1] / roojs-bootstrap-debug.js
index 4467b45..0be573d 100644 (file)
@@ -14081,6 +14081,7 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
                     
                     this.onLoad();
                     
+                    Roo.log('onload???');
                     
                 }else{
                     
@@ -40028,10 +40029,6 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         
         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(){
@@ -40057,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();
@@ -40108,6 +40105,18 @@ 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)
@@ -40207,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)
@@ -40247,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;
@@ -40260,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 = '';
         
@@ -40279,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();
         }
     },
@@ -40417,9 +40430,64 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         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.amountEl ? this.amountEl : this.el.select('.roo-money-amount-input', true).first();
+        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