remove debugging code
[roojs1] / Roo / bootstrap / FieldLabel.js
index 946c2cf..c59405c 100644 (file)
  * @cfg {String} html contents of the element
  * @cfg {String} tag tag of the element default label
  * @cfg {String} cls class of the element
- * @cfg {String} for label target 
+ * @cfg {String} target label target 
  * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
+ * @cfg {String} invalidClass DEPRICATED - BS4 uses is-invalid
+ * @cfg {String} validClass DEPRICATED - BS4 uses is-valid
+ * @cfg {String} iconTooltip default "This field is required"
+ * @cfg {String} indicatorpos (left|right) default left
  * 
  * @constructor
  * Create a new FieldLabel
@@ -45,27 +49,56 @@ Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component,  {
     tag: 'label',
     cls: '',
     html: '',
-    for: '',
+    target: '',
     allowBlank : true,
-    
+    invalidClass : 'has-warning',
+    validClass : 'has-success',
+    iconTooltip : 'This field is required',
+    indicatorpos : 'left',
     
     getAutoCreate : function(){
         
+       var cls = "";
+       if (!this.allowBlank) {
+           cls  = "visible";
+       }
+       
         var cfg = {
             tag : this.tag,
-            cls : this.cls,
-            for : this.for,
+            cls : 'roo-bootstrap-field-label ' + this.cls,
+            for : this.target,
             cn : [
                 {
                     tag : 'i',
-                    cls : ''
+                    cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star ' + cls,
+                    tooltip : this.iconTooltip
                 },
                 {
-                    
+                    tag : 'span',
+                    html : this.html
                 }
             ] 
         };
         
+        if(this.indicatorpos == 'right'){
+            var cfg = {
+                tag : this.tag,
+                cls : 'roo-bootstrap-field-label ' + this.cls,
+                for : this.target,
+                cn : [
+                    {
+                        tag : 'span',
+                        html : this.html
+                    },
+                    {
+                        tag : 'i',
+                        cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star '+ cls,
+                        tooltip : this.iconTooltip
+                    }
+                ] 
+            };
+        }
+        
         return cfg;
     },
     
@@ -73,40 +106,45 @@ Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component,  {
     {
         Roo.bootstrap.Element.superclass.initEvents.call(this);
         
-    },
-    
-    /**
-     * Mark this field as valid
-     */
-    markValid : function(){
-        if(!this.el  || this.preventMark){ // not rendered
-            return;
+        this.indicator = this.indicatorEl();
+        
+        if(this.indicator){
+            this.indicator.removeClass('visible');
+            this.indicator.addClass('invisible');
         }
         
-        this.el.removeClass([this.invalidClass, this.validClass]);
+        Roo.bootstrap.FieldLabel.register(this);
+    },
+    
+    indicatorEl : function()
+    {
+        var indicator = this.el.select('i.roo-required-indicator',true).first();
         
-        var feedback = this.el.select('.form-control-feedback', true).first();
-            
-        if(feedback){
-            this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
-        }
-
-        if(this.disabled || this.allowBlank){
-            return;
+        if(!indicator){
+            return false;
         }
         
-        this.el.addClass(this.validClass);
+        return indicator;
         
-        if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
-            
-            var feedback = this.el.select('.form-control-feedback', true).first();
-            
-            if(feedback){
-                this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
-                this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
-            }
-            
+    },
+    
+    /**
+     * Mark this field as valid
+     */
+    markValid : function()
+    {
+        if(this.indicator){
+            this.indicator.removeClass('visible');
+            this.indicator.addClass('invisible');
         }
+        if (Roo.bootstrap.version == 3) {
+           this.el.removeClass(this.invalidClass);
+           this.el.addClass(this.validClass);
+       } else {
+           this.el.removeClass('is-invalid');
+            this.el.addClass('is-valid');
+       }
+        
         
         this.fireEvent('valid', this);
     },
@@ -117,43 +155,54 @@ Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component,  {
      */
     markInvalid : function(msg)
     {
-        if(!this.el  || this.preventMark){ // not rendered
-            return;
+        if(this.indicator){
+            this.indicator.removeClass('invisible');
+            this.indicator.addClass('visible');
         }
+          if (Roo.bootstrap.version == 3) {
+           this.el.removeClass(this.validClass);
+           this.el.addClass(this.invalidClass);
+       } else {
+           this.el.removeClass('is-valid');
+            this.el.addClass('is-invalid');
+       }
         
-        this.el.removeClass([this.invalidClass, this.validClass]);
         
-        var feedback = this.el.select('.form-control-feedback', true).first();
-            
-        if(feedback){
-            this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
-        }
+        this.fireEvent('invalid', this, msg);
+    }
+    
+   
+});
 
-        if(this.disabled || this.allowBlank){
+Roo.apply(Roo.bootstrap.FieldLabel, {
+    
+    groups: {},
+    
+     /**
+    * register a FieldLabel Group
+    * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
+    */
+    register : function(label)
+    {
+        if(this.groups.hasOwnProperty(label.target)){
             return;
         }
-        
-        this.el.addClass(this.invalidClass);
-        
-        if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
-            
-            var feedback = this.el.select('.form-control-feedback', true).first();
-            
-            if(feedback){
-                this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
-                
-                if(this.getValue().length || this.forceFeedback){
-                    this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
-                }
-                
-            }
-            
+     
+        this.groups[label.target] = label;
+       
+    },
+    /**
+    * fetch a FieldLabel Group based on the target
+    * @param {string} target
+    * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
+    */
+    get: function(target) {
+        if (typeof(this.groups[target]) == 'undefined') {
+            return false;
         }
         
-        this.fireEvent('invalid', this, msg);
+        return this.groups[target] ;
     }
-    
-   
 });