sync
[roojs1] / Roo / bootstrap / CheckBox.js
index 64f44f3..ec0d284 100644 (file)
@@ -17,6 +17,7 @@
  * @cfg {Boolean} checked initnal the element
  * @cfg {Boolean} inline inline the element (default false)
  * @cfg {String} groupId the checkbox group id // normal just use for checkbox
+ * @cfg {String} tooltip label tooltip
  * 
  * @constructor
  * Create a new CheckBox
@@ -33,7 +34,13 @@ Roo.bootstrap.CheckBox = function(config){
         * @param {Roo.bootstrap.CheckBox} this This input
         * @param {Boolean} checked The new checked value
         */
-       check : true
+       check : true,
+       /**
+        * @event click
+        * Fires when the element is click.
+        * @param {Roo.bootstrap.CheckBox} this This input
+        */
+       click : true
     });
     
 };
@@ -47,6 +54,7 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
     checked: false,
     weight : false,
     inline: false,
+    tooltip : '',
     
     getAutoCreate : function()
     {
@@ -77,7 +85,7 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
                 tag: 'input',
                 type : 'hidden',
                 cls : 'roo-hidden-value',
-                value : this.checked ? this.valueOff : this.inputValue
+                value : this.checked ? this.inputValue : this.valueOff
             };
         }
         
@@ -92,10 +100,8 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
         
         if(this.checked){
             input.checked = this.checked;
-            
         }
         
-        
         if (this.name) {
             
             input.name = this.name;
@@ -153,23 +159,49 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
         
         if (align ==='left' && this.fieldLabel.length) {
 //                Roo.log("left and has label");
-                cfg.cn = [
-                    
-                    {
-                        tag: 'label',
-                        'for' :  id,
-                        cls : 'control-label col-md-' + this.labelWidth,
-                        html : this.fieldLabel
-                        
-                    },
-                    {
-                        cls : "col-md-" + (12 - this.labelWidth), 
-                        cn: [
-                            inputblock
-                        ]
-                    }
-                    
-                ];
+            cfg.cn = [
+                {
+                    tag: 'label',
+                    'for' :  id,
+                    cls : 'control-label',
+                    html : this.fieldLabel
+                },
+                {
+                    cls : "", 
+                    cn: [
+                        inputblock
+                    ]
+                }
+            ];
+            
+            if(this.labelWidth > 12){
+                cfg.cn[0].style = "width: " + this.labelWidth + 'px';
+            }
+            
+            if(this.labelWidth < 13 && this.labelmd == 0){
+                this.labelmd = this.labelWidth;
+            }
+            
+            if(this.labellg > 0){
+                cfg.cn[0].cls += ' col-lg-' + this.labellg;
+                cfg.cn[1].cls += ' col-lg-' + (12 - this.labellg);
+            }
+            
+            if(this.labelmd > 0){
+                cfg.cn[0].cls += ' col-md-' + this.labelmd;
+                cfg.cn[1].cls += ' col-md-' + (12 - this.labelmd);
+            }
+            
+            if(this.labelsm > 0){
+                cfg.cn[0].cls += ' col-sm-' + this.labelsm;
+                cfg.cn[1].cls += ' col-sm-' + (12 - this.labelsm);
+            }
+            
+            if(this.labelxs > 0){
+                cfg.cn[0].cls += ' col-xs-' + this.labelxs;
+                cfg.cn[1].cls += ' col-xs-' + (12 - this.labelxs);
+            }
+            
         } else if ( this.fieldLabel.length) {
 //                Roo.log(" label");
                 cfg.cn = [
@@ -180,7 +212,6 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
                         cls: 'control-label box-input-label',
                         //cls : 'input-group-addon',
                         html : this.fieldLabel
-                        
                     },
                     
                     inputblock
@@ -203,6 +234,10 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
                 html: this.boxLabel
             };
             
+            if(this.useFontAwesomeCheckBox) {
+                boxLabelCfg.cls = 'box-label fa-checkbox'
+            }
+            
             if(this.tooltip){
                 boxLabelCfg.tooltip = this.tooltip;
             }
@@ -263,9 +298,12 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
         }
     },
     
-    onClick : function()
+    onClick : function(e)
     {   
-        this.setChecked(!this.checked);
+        if(this.fireEvent('click', this, e) !== false){
+            this.setChecked(!this.checked);
+        }
+        
     },
     
     setChecked : function(state,suppressEvent)
@@ -359,6 +397,10 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
     
     validate : function()
     {
+        if(this.getVisibilityEl().hasClass('hidden')){
+            return true;
+        }
+        
         if(
                 this.disabled || 
                 (this.inputType == 'radio' && this.validateRadio()) ||
@@ -374,6 +416,10 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
     
     validateRadio : function()
     {
+        if(this.getVisibilityEl().hasClass('hidden')){
+            return true;
+        }
+        
         if(this.allowBlank){
             return true;
         }
@@ -397,6 +443,7 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
     {
         if(!this.groupId){
             return (this.getValue() == this.inputValue || this.allowBlank) ? true : false;
+            //return (this.getValue() == this.inputValue) ? true : false;
         }
         
         var group = Roo.bootstrap.CheckBox.get(this.groupId);
@@ -407,6 +454,15 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
         
         var r = false;
         
+        for(var i in group){
+            if(group[i].el.isVisible(true)){
+                r = false;
+                break;
+            }
+            
+            r = true;
+        }
+        
         for(var i in group){
             if(r){
                 break;
@@ -445,7 +501,7 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
             
             return;
         }
-        
+
         if(!this.groupId){
             this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
             this.el.findParent('.form-group', false, true).addClass(this.validClass);
@@ -453,7 +509,7 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
         }
         
         var group = Roo.bootstrap.CheckBox.get(this.groupId);
-            
+        
         if(!group){
             return;
         }
@@ -490,7 +546,6 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
             
         if(this.inputType == 'radio'){
             Roo.each(this.el.up('form').select('input[name='+this.name+']', true).elements, function(e){
-                Roo.log('marking invalid');
                 e.findParent('.form-group', false, true).removeClass([_this.invalidClass, _this.validClass]);
                 e.findParent('.form-group', false, true).addClass(_this.invalidClass);
             });
@@ -519,13 +574,13 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
     
     clearInvalid : function()
     {
-        Roo.log('is this runngin??');
-        
         Roo.bootstrap.Input.prototype.clearInvalid.call(this);
         
+        // this.el.findParent('.form-group', false, true).removeClass([this.invalidClass, this.validClass]);
+        
         var label = Roo.bootstrap.FieldLabel.get(this.name + '-group');
         
-        if (label) {
+        if (label && label.iconEl) {
             label.iconEl.removeClass(label.validClass);
             label.iconEl.removeClass(label.invalidClass);
         }
@@ -571,6 +626,15 @@ Roo.extend(Roo.bootstrap.CheckBox, Roo.bootstrap.Input,  {
         this.disabled = false;
         this.fireEvent("enable", this);
         return this;
+    },
+    
+    setBoxLabel : function(v)
+    {
+        this.boxLabel = v;
+        
+        if(this.rendered){
+            this.el.select('label.box-label',true).first().dom.innerHTML = (v === null || v === undefined ? '' : v);
+        }
     }
 
 });