Roo/bootstrap/ComboBox.js
[roojs1] / roojs-bootstrap-debug.js
index 388fc90..0be573d 100644 (file)
@@ -7675,7 +7675,6 @@ Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component,  {
         var target = false;
         
         items.each(function(f){
-            Roo.log(f.name);
             if(f.validate()){
                 return;
             }
@@ -7912,6 +7911,10 @@ clientValidation  Boolean          Applies to submit only.  Pass true to call fo
                         sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
                         field.setFromData(sd);
 
+                    } else if(field.setFromData && (field.store && !field.store.isLocal)) {
+                        
+                        field.setFromData(values);
+                        
                     } else {
                         field.setValue(values[id]);
                     }
@@ -7964,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..
@@ -7980,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) {
@@ -8916,8 +8926,8 @@ Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component,  {
         this.indicator = this.indicatorEl();
         
         if(this.indicator){
-            this.indicator.setVisibilityMode(Roo.Element.DISPLAY);
-            this.indicator.hide();
+            this.indicator.addClass('invisible');
+            
         }
  
         // reference to original value for reset
@@ -9225,7 +9235,8 @@ Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component,  {
         }
         
         if(this.indicator){
-            this.indicator.hide();
+            this.indicator.removeClass('visible');
+            this.indicator.addClass('invisible');
         }
         
         this.el.addClass(this.validClass);
@@ -9271,7 +9282,8 @@ Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component,  {
         }
         
         if(this.indicator){
-            this.indicator.show();
+            this.indicator.removeClass('invisible');
+            this.indicator.addClass('visible');
         }
         
         this.el.addClass(this.invalidClass);
@@ -14069,6 +14081,7 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
                     
                     this.onLoad();
                     
+                    Roo.log('onload???');
                     
                 }else{
                     
@@ -15229,6 +15242,14 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
             
             var default_text = '-- SELECT --';
             
+            if(this.placeholder.length){
+                default_text = this.placeholder;
+            }
+            
+            if(this.emptyTitle.length){
+                default_text += ' - ' + this.emptyTitle + ' -';
+            }
+            
             var opt = this.inputEl().createChild({
                 tag: 'option',
                 value : 0,
@@ -33352,8 +33373,7 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
         this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
         this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
         
-        this.indicatorEl().setVisibilityMode(Roo.Element.DISPLAY);
-        this.indicatorEl().hide();
+        this.indicatorEl().addClass('invisible');
         
         this.originalValue = this.getValue();
         
@@ -33405,7 +33425,8 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
     markValid : function()
     {
         if(this.labelEl.isVisible(true)){
-            this.indicatorEl().hide();
+            this.indicatorEl().removeClass('visible');
+            this.indicatorEl().addClass('invisible');
         }
         
         this.el.removeClass([this.invalidClass, this.validClass]);
@@ -33421,7 +33442,8 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
         }
         
         if(this.labelEl.isVisible(true)){
-            this.indicatorEl().show();
+            this.indicatorEl().removeClass('invisible');
+            this.indicatorEl().addClass('visible');
         }
         
         this.el.removeClass([this.invalidClass, this.validClass]);
@@ -35447,7 +35469,9 @@ Roo.extend(Roo.bootstrap.layout.Region, Roo.bootstrap.layout.Basic, {
     {
         panel = this.getPanel(panel);
         if(this.activePanel && this.activePanel != panel){
-            this.activePanel.setActiveState(false);
+            if(this.activePanel.setActiveState(false) === false){
+                return;
+            }
         }
         this.activePanel = panel;
         panel.setActiveState(true);
@@ -36490,10 +36514,13 @@ Roo.extend(Roo.bootstrap.panel.Content, Roo.bootstrap.Component, {
         this.active = active;
         this.setActiveClass(active);
         if(!active){
-            this.fireEvent("deactivate", this);
-        }else{
-            this.fireEvent("activate", this);
+            if(this.fireEvent("deactivate", this) === false){
+                return false;
+            }
+            return true;
         }
+        this.fireEvent("activate", this);
+        return true;
     },
     /**
      * Updates this panel's element
@@ -37654,7 +37681,7 @@ Roo.bootstrap.panel.TabItem = function(config){
     this.inner = Roo.get(els.inner, true);
     this.textEl = Roo.get(this.el.dom.firstChild, true);
     this.pnode = Roo.get(els.el.parentNode, true);
-    this.el.on("mousedown", this.onTabMouseDown, this);
+//    this.el.on("mousedown", this.onTabMouseDown, this);
     this.el.on("click", this.onTabClick, this);
     /** @private */
     if(config.closable){
@@ -39197,7 +39224,7 @@ Roo.bootstrap.PhoneInputData = function() {
 /**
  * @class Roo.bootstrap.PhoneInput
  * @extends Roo.bootstrap.TriggerField
- * An input combines with  dial-code selection
+ * An input with International dial-code selection
  
  * @cfg {String} defaultDialCode default '+852'
  * @cfg {Array} preferedCountries default []
@@ -39213,30 +39240,25 @@ Roo.bootstrap.PhoneInput = function(config) {
 
 Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
         
-        triggerList : true,
-        
         listWidth: undefined,
         
         selectedClass: 'active',
         
         invalidClass : "has-warning",
         
-        allCountries: [],
-        
-        dialCodeMapping: [],
-        
-        
         validClass: 'has-success',
         
-        defaultDialCode: '+852',
+        allowed: '0123456789',
         
-        preferedCountries: [
-            'hk',
-            'gb',
-            'us'
-        ],
+        /**
+         * @cfg {String} defaultDialCode The default dial code when initializing the input
+         */
+        defaultDialCode: '+852',
         
-        //white list / black list for countries?
+        /**
+         * @cfg {Array} preferedCountries A list of iso2 in array (e.g. ['hk','us']). Those related countries will show at the top of the input's choices
+         */
+        preferedCountries: false,
         
         getAutoCreate : function()
         {
@@ -39244,6 +39266,9 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
             var align = this.labelAlign || this.parentLabelAlign();
             var id = Roo.id();
             
+            this.allCountries = [];
+            this.dialCodeMapping = [];
+            
             for (var i = 0; i < data.length; i++) {
               var c = data[i];
               this.allCountries[i] = {
@@ -39430,6 +39455,14 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
                 })
             });
             
+            if(!this.preferedCountries) {
+                this.preferedCountries = [
+                    'hk',
+                    'gb',
+                    'us'
+                ];
+            }
+            
             var p = this.preferedCountries.reverse();
             
             if(p) {
@@ -39473,7 +39506,7 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
             
             this.list.on('mouseover', this.onViewOver, this);
             this.list.on('mousemove', this.onViewMove, this);
-            //this.list.on('scroll', this.onViewScroll, this);
+            this.inputEl().on("keyup", this.onKeyUp, this);
             
             this.tpl = '<li><a href="#"><div class="flag {iso2}"></div>{name} <span class="dial-code">+{dialCode}</span></a></li>';
 
@@ -39488,7 +39521,7 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
         onTriggerClick : function(e)
         {
             Roo.log('trigger click');
-            if(this.disabled || !this.triggerList){
+            if(this.disabled){
                 return;
             }
             
@@ -39664,17 +39697,17 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
         setValue : function(v)
         {
             var d = this.getDialCode(v);
-            this.value = v;
             
-            if(!d || d.length == 0 || v.length == 0) {
+            //invalid dial code
+            if(v.length == 0 || !d || d.length == 0) {
                 if(this.rendered){
                     this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
                     this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
                 }
-                this.validate();
                 return;
             }
             
+            //valid dial code
             this.setFlagClass(this.dialCodeMapping[d].iso2);
             this.setDialCode(d);
             this.inputEl().dom.value = v.replace('+'+d,'');
@@ -39690,7 +39723,6 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
             }
             
             var dialCode = "";
-            // only interested in international numbers (starting with a plus)
             if (v.charAt(0) != "+") {
                 return false;
             }
@@ -39713,10 +39745,749 @@ Roo.extend(Roo.bootstrap.PhoneInput, Roo.bootstrap.TriggerField, {
         reset : function()
         {
             this.setValue(this.defaultDialCode);
+            this.validate();
         },
         
         hiddenEl : function()
         {
             return this.el.select('input.hidden-tel-input',true).first();
+        },
+        
+        onKeyUp : function(e){
+            
+            var k = e.getKey();
+            var c = e.getCharCode();
+            
+            if(
+                    (String.fromCharCode(c) == '.' || String.fromCharCode(c) == '-') &&
+                    this.allowed.indexOf(String.fromCharCode(c)) === -1
+            ){
+                e.stopEvent();
+            }
+            
+            // if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
+            //     return;
+            // }
+            if(this.allowed.indexOf(String.fromCharCode(c)) === -1){
+                e.stopEvent();
+            }
+            
+            this.setValue(this.getValue());
+        }
+        
+});
+/**
+ * @class Roo.bootstrap.MoneyField
+ * @extends Roo.bootstrap.ComboBox
+ * Bootstrap MoneyField class
+ * 
+ * @constructor
+ * Create a new MoneyField.
+ * @param {Object} config Configuration options
+ */
+
+Roo.bootstrap.MoneyField = function(config) {
+    
+    Roo.bootstrap.MoneyField.superclass.constructor.call(this, config);
+    
+};
+
+Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
+    
+    /**
+     * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
+     */
+    allowDecimals : true,
+    /**
+     * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
+     */
+    decimalSeparator : ".",
+    /**
+     * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
+     */
+    decimalPrecision : 2,
+    /**
+     * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
+     */
+    allowNegative : true,
+    /**
+     * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
+     */
+    minValue : Number.NEGATIVE_INFINITY,
+    /**
+     * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
+     */
+    maxValue : Number.MAX_VALUE,
+    /**
+     * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
+     */
+    minText : "The minimum value for this field is {0}",
+    /**
+     * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
+     */
+    maxText : "The maximum value for this field is {0}",
+    /**
+     * @cfg {String} nanText Error text to display if the value is not a valid number.  For example, this can happen
+     * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
+     */
+    nanText : "{0} is not a valid number",
+    /**
+     * @cfg {Boolean} castInt (true|false) cast int if true (defalut true)
+     */
+    castInt : true,
+    
+    inputlg : 9,
+    inputmd : 9,
+    inputsm : 9,
+    inputxs : 6,
+    
+    store : false,
+    
+    getAutoCreate : function()
+    {
+        var align = this.labelAlign || this.parentLabelAlign();
+        
+        var id = Roo.id();
+
+        var cfg = {
+            cls: 'form-group',
+            cn: []
+        };
+
+        var input =  {
+            tag: 'input',
+            id : id,
+            cls : 'form-control roo-money-amount-input',
+            autocomplete: 'new-password'
+        };
+        
+        if (this.name) {
+            input.name = this.name;
+        }
+
+        if (this.disabled) {
+            input.disabled = true;
+        }
+
+        var clg = 12 - this.inputlg;
+        var cmd = 12 - this.inputmd;
+        var csm = 12 - this.inputsm;
+        var cxs = 12 - this.inputxs;
+        
+        var container = {
+            tag : 'div',
+            cls : 'row roo-money-field',
+            cn : [
+                {
+                    tag : 'div',
+                    cls : 'roo-money-currency column col-lg-' + clg + ' col-md-' + cmd + ' col-sm-' + csm + ' col-xs-' + cxs,
+                    cn : [
+                        {
+                            tag : 'div',
+                            cls: 'roo-select2-container input-group',
+                            cn: [
+                                {
+                                    tag : 'input',
+                                    cls : 'form-control roo-money-currency-input',
+                                    autocomplete: 'new-password'
+                                },
+                                {
+                                    tag :'span',
+                                    cls : 'input-group-addon',
+                                    cn : [
+                                        {
+                                            tag: 'span',
+                                            cls: 'caret'
+                                        }
+                                    ]
+                                }
+                            ]
+                        }
+                    ]
+                },
+                {
+                    tag : 'div',
+                    cls : 'roo-money-amount column col-lg-' + this.inputlg + ' col-md-' + this.inputmd + ' col-sm-' + this.inputsm + ' col-xs-' + this.inputxs,
+                    cn : [
+                        {
+                            tag: 'div',
+                            cls: this.hasFeedback ? 'has-feedback' : '',
+                            cn: [
+                                input
+                            ]
+                        }
+                    ]
+                }
+            ]
+            
+        };
+        
+        if (this.fieldLabel.length) {
+            var indicator = {
+                tag: 'i',
+                tooltip: 'This field is required'
+            };
+
+            var label = {
+                tag: 'label',
+                'for':  id,
+                cls: 'control-label',
+                cn: []
+            };
+
+            var label_text = {
+                tag: 'span',
+                html: this.fieldLabel
+            };
+
+            indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star left-indicator';
+            label.cn = [
+                indicator,
+                label_text
+            ];
+
+            if(this.indicatorpos == 'right') {
+                indicator.cls = 'roo-required-indicator text-danger fa fa-lg fa-star right-indicator';
+                label.cn = [
+                    label_text,
+                    indicator
+                ];
+            }
+
+            if(align == 'left') {
+                container = {
+                    tag: 'div',
+                    cn: [
+                        container
+                    ]
+                };
+
+                if(this.labelWidth > 12){
+                    label.style = "width: " + this.labelWidth + 'px';
+                }
+                if(this.labelWidth < 13 && this.labelmd == 0){
+                    this.labelmd = this.labelWidth;
+                }
+                if(this.labellg > 0){
+                    label.cls += ' col-lg-' + this.labellg;
+                    input.cls += ' col-lg-' + (12 - this.labellg);
+                }
+                if(this.labelmd > 0){
+                    label.cls += ' col-md-' + this.labelmd;
+                    container.cls += ' col-md-' + (12 - this.labelmd);
+                }
+                if(this.labelsm > 0){
+                    label.cls += ' col-sm-' + this.labelsm;
+                    container.cls += ' col-sm-' + (12 - this.labelsm);
+                }
+                if(this.labelxs > 0){
+                    label.cls += ' col-xs-' + this.labelxs;
+                    container.cls += ' col-xs-' + (12 - this.labelxs);
+                }
+            }
+        }
+
+        cfg.cn = [
+            label,
+            container
+        ];
+
+        var settings = this;
+
+        ['xs','sm','md','lg'].map(function(size){
+            if (settings[size]) {
+                cfg.cls += ' col-' + size + '-' + settings[size];
+            }
+        });
+        
+        return cfg;
+        
+    },
+    
+    initEvents : function()
+    {
+        this.indicator = this.indicatorEl();
+        
+        this.initCurrencyEvent();
+        
+        this.initNumberEvent();
+        
+    },
+    
+    initCurrencyEvent : function()
+    {
+        if (!this.store) {
+            throw "can not find store for combo";
         }
+        
+        this.store = Roo.factory(this.store, Roo.data);
+        this.store.parent = this;
+        
+        this.createList();
+        
+        this.triggerEl = this.el.select('.input-group-addon', true).first();
+        
+        this.triggerEl.on("click", this.onTriggerClick, this, { preventDefault : true });
+        
+        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
+        });
+        
+        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){
+            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.inputEl().on("keypress", keyPress, this);
+        
+    },
+    
+    onTriggerClick : function(e)
+    {   
+        if(this.disabled){
+            return;
+        }
+        
+        this.page = 0;
+        this.loadNext = false;
+        
+        if(this.isExpanded()){
+            this.collapse();
+            return;
+        }
+        
+        this.hasFocus = true;
+        
+        if(this.triggerAction == 'all') {
+            this.doQuery(this.allQuery, true);
+            return;
+        }
+        
+        this.doQuery(this.getRawValue());
+    },
+    
+    getCurrency : function()
+    {   
+        var v = this.currencyEl().getValue();
+        
+        return v;
+    },
+    
+    restrictHeight : function()
+    {
+        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);
+        }
+    },
+    
+    onSelect : function(record, index){
+        
+        if(this.fireEvent('beforeselect', this, record, index) !== false){
+        
+            this.setFromCurrencyData(index > -1 ? record.data : false);
+            
+            this.collapse();
+            
+            this.fireEvent('select', this, record, index);
+        }
+    },
+    
+    setFromCurrencyData : function(o)
+    {
+        var currency = '';
+        
+        this.lastCurrency = o;
+        
+        if (this.currencyField) {
+            currency = !o || typeof(o[this.currencyField]) == 'undefined' ? '' : o[this.currencyField];
+        } else {
+            Roo.log('no  currencyField value set for '+ (this.name ? this.name : this.id));
+        }
+        
+        this.lastSelectionText = currency;
+        
+        this.setCurrency(currency);
+    },
+    
+    setFromData : function(o)
+    {
+        var c = {};
+        
+        c[this.currencyField] = !o || typeof(o[this.currencyName]) == 'undefined' ? '' : o[this.currencyName];
+        
+        this.setFromCurrencyData(c);
+        
+        var value = '';
+        
+        if (this.name) {
+            value = !o || typeof(o[this.name]) == 'undefined' ? '' : o[this.name];
+        } else {
+            Roo.log('no value set for '+ (this.name ? this.name : this.id));
+        }
+        
+        this.setValue(value);
+        
+    },
+    
+    setCurrency : function(v)
+    {   
+        this.currencyValue = v;
+        
+        if(this.rendered){
+            this.currencyEl().dom.value = (v === null || v === undefined ? '' : v);
+            this.validate();
+        }
+    },
+    
+    setValue : function(v)
+    {
+        v = this.fixPrecision(v);
+        
+        v = String(v).replace(".", this.decimalSeparator);
+        
+        this.value = v;
+        
+        if(this.rendered){
+            this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
+            this.validate();
+        }
+    },
+    
+    getRawValue : function()
+    {
+        var v = this.inputEl().getValue();
+        
+        return v;
+    },
+    
+    getValue : function()
+    {
+        return this.fixPrecision(this.parseValue(this.getRawValue()));
+    },
+    
+    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);
+    },
+    
+    validateValue : function(value)
+    {
+        if(!Roo.bootstrap.MoneyField.superclass.validateValue.call(this, value)){
+            return false;
+        }
+        
+        var num = this.parseValue(value);
+        
+        if(isNaN(num)){
+            this.markInvalid(String.format(this.nanText, value));
+            return false;
+        }
+        
+        if(num < this.minValue){
+            this.markInvalid(String.format(this.minText, this.minValue));
+            return false;
+        }
+        
+        if(num > this.maxValue){
+            this.markInvalid(String.format(this.maxText, this.maxValue));
+            return false;
+        }
+        
+        return true;
+    },
+    
+    validate : function()
+    {
+        if(this.disabled){
+            this.markValid();
+            return true;
+        }
+        
+        var currency = this.getCurrency();
+        
+        if(this.validateValue(this.getRawValue()) && currency.length){
+            this.markValid();
+            return true;
+        }
+        
+        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