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  * @cfg {Boolean} allowBlank (true|false) target allowBlank default true
17  * @cfg {String} invalidClass default "text-danger fa fa-lg fa-exclamation-triangle"
18  * @cfg {String} validClass default "text-success fa fa-lg fa-check"
19  * 
20  * @constructor
21  * Create a new FieldLabel
22  * @param {Object} config The config object
23  */
24
25 Roo.bootstrap.FieldLabel = function(config){
26     Roo.bootstrap.Element.superclass.constructor.call(this, config);
27     
28     this.addEvents({
29             /**
30              * @event invalid
31              * Fires after the field has been marked as invalid.
32              * @param {Roo.form.FieldLabel} this
33              * @param {String} msg The validation message
34              */
35             invalid : true,
36             /**
37              * @event valid
38              * Fires after the field has been validated with no errors.
39              * @param {Roo.form.FieldLabel} this
40              */
41             valid : true
42         });
43 };
44
45 Roo.extend(Roo.bootstrap.FieldLabel, Roo.bootstrap.Component,  {
46     
47     tag: 'label',
48     cls: '',
49     html: '',
50     for: '',
51     allowBlank : true,
52     invalidClass : 'text-danger fa fa-lg fa-exclamation-triangle',
53     validClass : 'text-success fa fa-lg fa-check',
54     
55     getAutoCreate : function(){
56         
57         var cfg = {
58             tag : this.tag,
59             cls : 'roo-bootstrap-field-label ' + this.cls,
60             for : this.for,
61             cn : [
62                 {
63                     tag : 'i',
64                     cls : ''
65                 },
66                 {
67                     tag : 'span',
68                     html : this.html
69                 }
70             ] 
71         };
72         
73         return cfg;
74     },
75     
76     initEvents: function() 
77     {
78         Roo.bootstrap.Element.superclass.initEvents.call(this);
79         
80         this.iconEl = this.el.select('i', true).first();
81         
82         this.iconEl.setVisibilityMode(Roo.Element.DISPLAY).hide();
83         
84         Roo.bootstrap.FieldLabel.register(this);
85         
86         Roo.log(Roo.bootstrap.FieldLabel.register);
87     },
88     
89     /**
90      * Mark this field as valid
91      */
92     markValid : function()
93     {
94         this.iconEl.show();
95         
96         this.iconEl.removeClass(this.invalidClass);
97         
98         this.iconEl.addClass(this.validClass);
99         
100         this.fireEvent('valid', this);
101     },
102     
103     /**
104      * Mark this field as invalid
105      * @param {String} msg The validation message
106      */
107     markInvalid : function(msg)
108     {
109         this.iconEl.show();
110         
111         this.iconEl.removeClass(this.validClass);
112         
113         this.iconEl.addClass(this.invalidClass);
114         
115         this.fireEvent('invalid', this, msg);
116     }
117     
118    
119 });
120
121 Roo.apply(Roo.bootstrap.FieldLabel, {
122     
123     groups: {},
124     
125      /**
126     * register a FieldLabel Group
127     * @param {Roo.bootstrap.FieldLabel} the FieldLabel to add
128     */
129     register : function(label)
130     {
131         if(typeof(this.groups[label.for]) == 'undefined'){
132             this.groups[label.for] = {};
133         }
134         
135         if(this.groups.hasOwnProperty(label.for)){
136             return;
137         }
138         Roo.log('register???!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
139         Roo.log(label);
140         this.groups[label.for] = label;
141         
142     },
143     /**
144     * fetch a FieldLabel Group based on the for
145     * @param {string} for
146     * @returns {Roo.bootstrap.FieldLabel} the CheckBox group
147     */
148     get: function(name) {
149         if (typeof(this.groups[name]) == 'undefined') {
150             return false;
151         }
152         
153         return this.groups[name] ;
154     }
155     
156     
157 });
158
159  
160
161