sync
[roojs1] / Roo / bootstrap / RadioSet.js
index 5fe94c8..ce57bba 100644 (file)
@@ -21,7 +21,7 @@
 Roo.bootstrap.RadioSet = function(config){
     
     Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
-
+    
     this.radioes = [];
     
     Roo.bootstrap.RadioSet.register(this);
@@ -33,7 +33,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
     });
     
 };
@@ -46,8 +54,6 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
     
     weight : '',
     
-    fieldLabel : '',
-    
     indicatorpos : 'left',
     
     getAutoCreate : function()
@@ -62,21 +68,23 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
                 }
             ]
         };
-        
-        if(this.indicatorpos == 'left'){
-            label.cn.unshift({
-                tag : 'i',
-                cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
-                tooltip : 'This field is required'
-            });
-        } else {
-            label.cn.push({
-                tag : 'i',
-                cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
-                tooltip : 'This field is required'
-            });
+        if (Roo.bootstrap.version == 3) {
+            
+            
+            if(this.indicatorpos == 'left'){
+                label.cn.unshift({
+                    tag : 'i',
+                    cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
+                    tooltip : 'This field is required'
+                });
+            } else {
+                label.cn.push({
+                    tag : 'i',
+                    cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
+                    tooltip : 'This field is required'
+                });
+            }
         }
-        
         var items = {
             tag : 'div',
             cls : 'roo-radio-set-items'
@@ -86,14 +94,40 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
         
         if (align === 'left' && this.fieldLabel.length) {
             
-            label.cls += ' col-md-' + this.labelWidth;
-            
             items = {
-                cls : "col-md-" + (12 - this.labelWidth)
+                cls : "roo-radio-set-right"
                 cn: [
                     items
                 ]
             };
+            
+            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;
+                items.cls += ' col-lg-' + (12 - this.labellg);
+            }
+            
+            if(this.labelmd > 0){
+                label.cls += ' col-md-' + this.labelmd;
+                items.cls += ' col-md-' + (12 - this.labelmd);
+            }
+            
+            if(this.labelsm > 0){
+                label.cls += ' col-sm-' + this.labelsm;
+                items.cls += ' col-sm-' + (12 - this.labelsm);
+            }
+            
+            if(this.labelxs > 0){
+                label.cls += ' col-xs-' + this.labelxs;
+                items.cls += ' col-xs-' + (12 - this.labelxs);
+            }
         }
         
         var cfg = {
@@ -112,20 +146,42 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
             ]
         };
         
+        if(this.weight.length){
+            cfg.cls += ' roo-radio-' + this.weight;
+        }
+        
         if(this.inline) {
             cfg.cls += ' roo-radio-set-inline';
         }
         
+        var settings=this;
+        ['xs','sm','md','lg'].map(function(size){
+            if (settings[size]) {
+                cfg.cls += ' col-' + size + '-' + settings[size];
+            }
+        });
+        
         return cfg;
         
     },
 
     initEvents : function()
     {
+        this.labelEl = this.el.select('.roo-radio-set-label', true).first();
+        this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
+        
+        if(!this.fieldLabel.length){
+            this.labelEl.hide();
+        }
+        
         this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
         this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
         
-        this.indicatorEl().hide();
+        this.indicator = this.indicatorEl();
+        
+        if(this.indicator){
+            this.indicator.addClass('invisible');
+        }
         
         this.originalValue = this.getValue();
         
@@ -145,14 +201,14 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
     {
         this.radioes.push(item);
         
-        if(this.inline){
-            item.el.addClass('radio-inline');
-        }
-        
     },
     
     validate : function()
     {   
+        if(this.getVisibilityEl().hasClass('hidden')){
+            return true;
+        }
+        
         var valid = false;
         
         Roo.each(this.radioes, function(i){
@@ -164,7 +220,11 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
             return false;
         });
         
-        if(this.disabled || this.allowBlank || valid){
+        if(this.allowBlank) {
+            return true;
+        }
+        
+        if(this.disabled || valid){
             this.markValid();
             return true;
         }
@@ -176,10 +236,17 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
     
     markValid : function()
     {
-        this.indicatorEl().hide();
+        if(this.labelEl.isVisible(true) && this.indicatorEl()){
+            this.indicatorEl().removeClass('visible');
+            this.indicatorEl().addClass('invisible');
+        }
+        
         this.el.removeClass([this.invalidClass, this.validClass]);
         this.el.addClass(this.validClass);
-        
+        if (Roo.bootstrap.version == 3) {
+            this.el.removeClass(['is-invalid','is-valid']);
+            this.el.addClass(['is-valid']);
+        }
         this.fireEvent('valid', this);
     },
     
@@ -189,20 +256,39 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
             return;
         }
         
-        this.indicatorEl().show();
-        this.el.removeClass([this.invalidClass, this.validClass]);
-        this.el.addClass(this.invalidClass);
+        if(this.labelEl.isVisible(true) && this.indicatorEl()){
+            this.indicatorEl().removeClass('invisible');
+            this.indicatorEl().addClass('visible');
+        }
+        if (Roo.bootstrap.version == 3) {
+            this.el.removeClass([this.invalidClass, this.validClass]);
+            this.el.addClass(this.invalidClass);
+        }
+        this.el.removeClass(['is-invalid','is-valid']);
+        this.el.addClass(['is-invalid']);
         
         this.fireEvent('invalid', this, msg);
         
     },
     
     setValue : function(v, suppressEvent)
-    {
+    {   
+        if(this.value === v){
+            return;
+        }
+        
+        this.value = v;
+        
+        if(this.rendered){
+            this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
+        }
+        
         Roo.each(this.radioes, function(i){
-            
             i.checked = false;
             i.el.removeClass('checked');
+        });
+        
+        Roo.each(this.radioes, function(i){
             
             if(i.value === v || i.value.toString() === v.toString()){
                 i.checked = true;
@@ -211,12 +297,24 @@ Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input,  {
                 if(suppressEvent !== true){
                     this.fireEvent('check', this, i);
                 }
+                
+                return false;
             }
             
         }, this);
         
-        Roo.bootstrap.RadioSet.superclass.setValue.call(this)
+        this.validate();
+    },
+    
+    clearInvalid : function(){
+        
+        if(!this.el || this.preventMark){
+            return;
+        }
         
+        this.el.removeClass([this.invalidClass]);
+        
+        this.fireEvent('valid', this);
     }
     
 });