Roo/bootstrap/ComboBox.js
[roojs1] / roojs-bootstrap-debug.js
index 2332e43..7d08a7d 100644 (file)
@@ -369,18 +369,24 @@ Roo.extend(Roo.bootstrap.Component, Roo.BoxComponent,  {
      */
     show : function()
     {
-        if (this.el) {
-            this.el.removeClass('hidden');
+        if(!this.getEl()){
+            return;
         }
+        
+        this.getEl().removeClass('hidden');
+        
     },
     /**
      * Hide a component - adds 'hidden' class
      */
     hide: function()
     {
-        if (this.el && !this.el.hasClass('hidden')) {
-            this.el.addClass('hidden');
+        if(!this.getEl() || this.getEl().hasClass('hidden')){
+            return;
         }
+        
+        this.getEl().addClass('hidden');
+        
     }
 });
 
@@ -1374,6 +1380,41 @@ Roo.extend(Roo.bootstrap.Container, Roo.bootstrap.Component,  {
         e.preventDefault();
         
         this.fireEvent('click', this, e);
+    },
+    
+    allChildren : function()
+    {
+        var r=new Roo.util.MixedCollection(false, function(o){
+            return o.id || (o.id = Roo.id());
+        });
+        var iter = function(el) {
+            if (el.inputEl) {
+                r.add(el);
+            }
+            if (!el.items) {
+                return;
+            }
+            Roo.each(el.items,function(e) {
+                iter(e);
+            });
+        };
+
+        iter(this);
+        return r;
+    },
+    
+    checkEmpty : function()
+    {
+        var items = this.allChildren();
+        var isEmpty = true;
+        
+        items.each(function(f){
+            if(f.el.isVisible()) {
+                isEmpty = false;
+            }
+        });
+        
+        return isEmpty;
     }
    
 });
@@ -2325,6 +2366,12 @@ Roo.extend(Roo.bootstrap.Menu, Roo.bootstrap.Component,  {
     {
         Roo.log(this.el);
         return this.el;
+    },
+    
+    clear : function()
+    {
+        this.getEl().dom.innerHTML = '';
+        this.menuitems.clear();
     }
 });
 
@@ -7557,6 +7604,7 @@ Roo.form.Action.ACTION_TYPES = {
 
 
 Roo.bootstrap.Form = function(config){
+    
     Roo.bootstrap.Form.superclass.constructor.call(this, config);
     
     Roo.bootstrap.Form.popover.apply();
@@ -7591,7 +7639,6 @@ Roo.bootstrap.Form = function(config){
          */
         actioncomplete : true
     });
-
 };
 
 Roo.extend(Roo.bootstrap.Form, Roo.bootstrap.Component,  {
@@ -8063,8 +8110,6 @@ clientValidation  Boolean          Applies to submit only.  Pass true to call fo
            f.clearInvalid();
         });
 
-
-
         return this;
     },
 
@@ -8101,13 +8146,50 @@ clientValidation  Boolean          Applies to submit only.  Pass true to call fo
             Roo.each(el.items,function(e) {
                 iter(e);
             });
-
-
         };
 
         iter(this);
         return r;
-        
+    },
+    
+    hideFields : function(items)
+    {
+        Roo.each(items, function(i){
+            
+            var f = this.findField(i);
+            
+            if(!f){
+                return;
+            }
+            
+            if(f.xtype == 'DateField'){
+                f.setVisible(false);
+                return;
+            }
+            
+            f.hide();
+            
+        }, this);
+    },
+    
+    showFields : function(items)
+    {
+        Roo.each(items, function(i){
+            
+            var f = this.findField(i);
+            
+            if(!f){
+                return;
+            }
+            
+            if(f.xtype == 'DateField'){
+                f.setVisible(true);
+                return;
+            }
+            
+            f.show();
+            
+        }, this);
     }
 
 });
@@ -9040,12 +9122,17 @@ Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component,  {
      * @param {Mixed} value The value to validate
      * @return {Boolean} True if the value is valid, else false
      */
-    validateValue : function(value){
+    validateValue : function(value)
+    {
+        if(this.getEl().hasClass('hidden')){
+            return true;
+        }
+        
         if(value.length < 1)  { // if it's blank
             if(this.allowBlank){
                 return true;
-            }            
-            return this.inputEl().hasClass('hide') ? true : false;
+            }
+            return false;
         }
         
         if(value.length < this.minLength){
@@ -9076,8 +9163,6 @@ Roo.extend(Roo.bootstrap.Input, Roo.bootstrap.Component,  {
         
         return true;
     },
-
-    
     
      // private
     fireKey : function(e){
@@ -14605,6 +14690,10 @@ Roo.extend(Roo.bootstrap.ComboBox, Roo.bootstrap.TriggerField, {
     
     validate : function()
     {
+        if(this.getEl().hasClass('hidden')){
+            return true;
+        }
+        
         var v = this.getRawValue();
         
         if(this.multiple){
@@ -19080,6 +19169,10 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input,  {
     
     validateValue : function(value)
     {
+        if(this.getEl().hasClass('hidden')){
+            return true;
+        }
+        
         if(value.length < 1)  {
             if(this.allowBlank){
                 return true;
@@ -19124,6 +19217,21 @@ Roo.extend(Roo.bootstrap.DateField, Roo.bootstrap.Input,  {
         
         
         return true;
+    },
+    
+    setVisible : function(visible)
+    {
+        if(!this.getEl()){
+            return;
+        }
+        
+        this.getEl().removeClass('hidden');
+        
+        if(visible){
+            return;
+        }
+        
+        this.getEl().addClass('hidden');
     }
    
 });
@@ -20896,9 +21004,11 @@ Roo.extend(Roo.bootstrap.Radio, Roo.bootstrap.Component, {
         
     },
     
-    onClick : function()
+    onClick : function(e)
     {
-        this.setChecked(true);
+        if(this.parent().fireEvent('click', this.parent(), this, e) !== false){
+            this.setChecked(true);
+        }
     },
     
     setChecked : function(state, suppressEvent)
@@ -24441,7 +24551,8 @@ Roo.extend(Roo.bootstrap.PagingToolbar, Roo.bootstrap.NavSimplebar, {
     // private
     onLoad : function(ds, r, o)
     {
-        this.cursor = o.params ? o.params.start : 0;
+        this.cursor = o.params.start ? o.params.start : 0;
+        
         var d = this.getPageData(),
             ap = d.activePage,
             ps = d.pages;
@@ -32974,8 +33085,7 @@ Roo.extend(Roo.bootstrap.Brick, Roo.bootstrap.Component,  {
  /*
  * - LGPL
  *
- * Input
- * 
+ * Number field 
  */
 
 /**
@@ -33013,6 +33123,11 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
      * @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)
      */
@@ -33039,19 +33154,20 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
      */
     castInt : true,
     /**
-     * @cfg {Boolean} allowThousandsDelimiter (true|false) display thousands delimiter if true (e.g. "100,000") (defalut false)
+     * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
      */
-    allowThousandsDelimiter : false,
+    thousandsDelimiter : false,
     /**
-     * @cfg {String} symbol of thousandsDelimiter
+     * @cfg {String} valueAlign alignment of value
      */
-    thousandsDelimiter : ",",
+    valueAlign : "left",
 
     getAutoCreate : function()
     {
         var hiddenInput = {
             tag: 'input',
             type: 'hidden',
+            id: Roo.id(),
             cls: 'hidden-number-input'
         };
         
@@ -33063,12 +33179,12 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
         
         var cfg = Roo.bootstrap.NumberField.superclass.getAutoCreate.call(this);
         
+        this.name = hiddenInput.name;
+        
         if(cfg.cn.length > 0) {
             cfg.cn.push(hiddenInput);
         }
         
-        Roo.log(cfg);
-        
         return cfg;
     },
 
@@ -33087,6 +33203,10 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
             allowed += "-";
         }
         
+        if(this.thousandsDelimiter) {
+            allowed += ",";
+        }
+        
         this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
         
         var keyPress = function(e){
@@ -33144,17 +33264,31 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
 
     getValue : function()
     {
-        return this.fixPrecision(this.parseValue(this.inputEl().getValue()));
+        var v = this.hiddenEl().getValue();
+        
+        return this.fixPrecision(this.parseValue(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){
@@ -33165,8 +33299,24 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
 
     setValue : function(v)
     {
-        v = this.fixPrecision(v);
-        Roo.bootstrap.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
+        v = String(this.fixPrecision(v)).replace(".", this.decimalSeparator);
+        
+        this.value = v;
+        
+        if(this.rendered){
+            
+            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();
+        }
     },
 
     decimalPrecisionFcn : function(v)
@@ -33181,35 +33331,13 @@ Roo.extend(Roo.bootstrap.NumberField, Roo.bootstrap.Input, {
         }
         
         var v = this.parseValue(this.getRawValue());
-        if(v){
-            this.setValue(v);
-        }
-    },
-    
-    addThousandsDelimiter : function(v)
-    {
-        if(!this.allowThousandsDelimiter) {
-            return v;
-        }
         
-        v += "";
-        
-        var x = v.split(".");
-        
-        var x1 = x[0];
-        
-        var x2 = x.length > 1 ? "." + x[1] : "";
-        
-        var rgx = /(\d+)(\d{3})/;
-        
-        while (rgx.test(x1)) {
-            x1 = x1.replace(rgx, "$1" + this.thousandsDelimiter + "$2");
+        if(v || v === 0){
+            this.setValue(v);
         }
-        
-        return x1 + x2;
     },
     
-    inputEl: function ()
+    hiddenEl : function()
     {
         return this.el.select('input.hidden-number-input',true).first();
     }
@@ -33447,7 +33575,15 @@ Roo.bootstrap.RadioSet = function(config){
         * @param {Roo.bootstrap.RadioSet} this This radio
         * @param {Roo.bootstrap.Radio} item The checked item
         */
-       check : true
+       check : true,
+       /**
+        * @event click
+        * Fires when the element is click.
+        * @param {Roo.bootstrap.RadioSet} this This radio set
+        * @param {Roo.bootstrap.Radio} item The checked item
+        * @param {Roo.EventObject} e The event object
+        */
+       click : true
     });
     
 };
@@ -33605,6 +33741,10 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
     
     validate : function()
     {   
+        if(this.getEl().hasClass('hidden')){
+            return true;
+        }
+        
         var valid = false;
         
         Roo.each(this.radioes, function(i){
@@ -40022,7 +40162,7 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
     /**
      * @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)
      */
@@ -40057,6 +40197,10 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
      * value should be in lkey
      */
     defaultCurrency : false,
+    /**
+     * @cfg {String} thousandsDelimiter Symbol of thousandsDelimiter
+     */
+    thousandsDelimiter : false,
     
     
     inputlg : 9,
@@ -40084,8 +40228,15 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
             autocomplete: 'new-password'
         };
         
+        var hiddenInput = {
+            tag: 'input',
+            type: 'hidden',
+            id: Roo.id(),
+            cls: 'hidden-number-input'
+        };
+        
         if (this.name) {
-            input.name = this.name;
+            hiddenInput.name = this.name;
         }
 
         if (this.disabled) {
@@ -40214,9 +40365,10 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
 
         cfg.cn = [
             label,
-            container
+            container,
+            hiddenInput
         ];
-
+        
         var settings = this;
 
         ['xs','sm','md','lg'].map(function(size){
@@ -40226,7 +40378,6 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         });
         
         return cfg;
-        
     },
     
     initEvents : function()
@@ -40236,7 +40387,6 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         this.initCurrencyEvent();
         
         this.initNumberEvent();
-        
     },
     
     initCurrencyEvent : function()
@@ -40527,7 +40677,17 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         this.value = v;
         
         if(this.rendered){
-            this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
+            
+            this.hiddenEl().dom.value = (v === null || v === undefined ? '' : v);
+            
+            this.inputEl().dom.value = Roo.util.Format.number(v, this.decimalPrecision, 
+                this.thousandsDelimiter || ','
+            );
+            
+            if(this.allowBlank && !v) {
+                this.inputEl().dom.value = '';
+            }
+            
             this.validate();
         }
     },
@@ -40623,7 +40783,7 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
         
         var v = this.parseValue(this.getRawValue());
         
-        if(v){
+        if(v || v == 0){
             this.setValue(v);
         }
     },
@@ -40659,6 +40819,11 @@ Roo.extend(Roo.bootstrap.MoneyField, Roo.bootstrap.ComboBox, {
     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