Roo/bootstrap/FieldLabel.js
[roojs1] / Roo / bootstrap / FieldLabel.js
1 /*
2  * - LGPL
3  *
4  * FieldLabel
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.FieldLabel
10  * @extends Roo.bootstrap.Component
11  * Bootstrap FieldLabel class
12  * @cfg {String} html contents of the element
13  * @cfg {String} tag tag of the element default label
14  * @cfg {String} cls class of the element
15  * @cfg {String} for label target 
16  * 
17  * @constructor
18  * Create a new FieldLabel
19  * @param {Object} config The config object
20  */
21
22 Roo.bootstrap.FieldLabel = function(config){
23     Roo.bootstrap.Element.superclass.constructor.call(this, config);
24     
25     this.addEvents({
26             /**
27              * @event invalid
28              * Fires after the field has been marked as invalid.
29              * @param {Roo.form.FieldLabel} this
30              * @param {String} msg The validation message
31              */
32             invalid : true,
33             /**
34              * @event valid
35              * Fires after the field has been validated with no errors.
36              * @param {Roo.form.FieldLabel} this
37              */
38             valid : true
39         });
40 };
41
42 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component,  {
43     
44     tag: 'label',
45     cls: '',
46     html: '',
47     for: '',
48     
49     getAutoCreate : function(){
50         
51         var cfg = {
52             tag : this.tag,
53             cls : this.cls,
54             for : this.for,
55             cn : [
56                 {
57                     tag : 'i'
58                 }
59             ] 
60         };
61         
62         return cfg;
63     },
64     
65     initEvents: function() 
66     {
67         Roo.bootstrap.Element.superclass.initEvents.call(this);
68         
69     },
70     
71     /**
72      * Mark this field as valid
73      */
74     markValid : function(){
75         if(!this.el  || this.preventMark){ // not rendered
76             return;
77         }
78         
79         this.el.removeClass([this.invalidClass, this.validClass]);
80         
81         var feedback = this.el.select('.form-control-feedback', true).first();
82             
83         if(feedback){
84             this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
85         }
86
87         if(this.disabled || this.allowBlank){
88             return;
89         }
90         
91         this.el.addClass(this.validClass);
92         
93         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank && (this.getValue().length || this.forceFeedback)){
94             
95             var feedback = this.el.select('.form-control-feedback', true).first();
96             
97             if(feedback){
98                 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
99                 this.el.select('.form-control-feedback', true).first().addClass([this.validFeedbackClass]);
100             }
101             
102         }
103         
104         this.fireEvent('valid', this);
105     },
106     
107     /**
108      * Mark this field as invalid
109      * @param {String} msg The validation message
110      */
111     markInvalid : function(msg)
112     {
113         if(!this.el  || this.preventMark){ // not rendered
114             return;
115         }
116         
117         this.el.removeClass([this.invalidClass, this.validClass]);
118         
119         var feedback = this.el.select('.form-control-feedback', true).first();
120             
121         if(feedback){
122             this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
123         }
124
125         if(this.disabled || this.allowBlank){
126             return;
127         }
128         
129         this.el.addClass(this.invalidClass);
130         
131         if(this.hasFeedback && this.inputType != 'hidden' && !this.allowBlank){
132             
133             var feedback = this.el.select('.form-control-feedback', true).first();
134             
135             if(feedback){
136                 this.el.select('.form-control-feedback', true).first().removeClass([this.invalidFeedbackClass, this.validFeedbackClass]);
137                 
138                 if(this.getValue().length || this.forceFeedback){
139                     this.el.select('.form-control-feedback', true).first().addClass([this.invalidFeedbackClass]);
140                 }
141                 
142             }
143             
144         }
145         
146         this.fireEvent('invalid', this, msg);
147     }
148     
149    
150 });
151
152  
153
154