70e08c5dd1ba73b3302ddabfa4098ea38de247c1
[roojs1] / Roo / bootstrap / RadioItem.js
1 /*
2  * - LGPL
3  *
4  * RadioItem
5  * 
6  */
7
8 /**
9  * @class Roo.bootstrap.RadioItem
10  * @extends Roo.bootstrap.Component
11  * Bootstrap RadioItem class
12  * @cfg {String} boxLabel - the label associated
13  * @cfg {String} value - the value of radio
14  * 
15  * @constructor
16  * Create a new RadioItem
17  * @param {Object} config The config object
18  */
19 Roo.bootstrap.RadioItem = function(config){
20     Roo.bootstrap.RadioItem.superclass.constructor.call(this, config);
21     
22 };
23
24 Roo.extend(Roo.bootstrap.RadioItem, Roo.bootstrap.Component,  {
25     
26     boxLabel : '',
27     value : '',
28     
29     getAutoCreate : function()
30     {
31         var cfg = {
32                 tag : 'div',
33                 cls : 'form-group radio roo-radio-set-item',
34                 cn : [
35                     {
36                         tag : 'input',
37                         cls : 'roo-radio roo-radio-set-item-input',
38                         type : 'radio',
39                         value : this.value,
40                     },
41                     {
42                         tag : 'label',
43                         cls : 'box-label roo-radio-set-item-box-label',
44                         html : this.boxLabel
45                     }
46                 ]
47         };
48         
49         return cfg;
50     },
51     
52     initEvents : function() 
53     {
54         this.parent().register(this);
55         
56         this.inputEl().on('click', this.onClick, this);
57         
58         if (this.boxLabel) {
59             this.el.select('.roo-radio-set-item-box-label',true).first().on('click', this.onClick, this);
60         }
61     },
62     
63     inputEl : function()
64     {
65         return this.el.select('.roo-radio-set-item-input', true).first();
66     },
67     
68     onClick : function()
69     {
70         this.setChecked(true);
71     },
72     
73     setChecked : function(state, suppressEvent)
74     {
75         Roo.each(this.parent().items, function(i){
76             i.checked = false;
77             i.inputEl().dom.checked = false; 
78         });
79         
80         this.checked = state;
81         this.inputEl().dom.checked = state;
82
83         if(suppressEvent !== true){
84             this.fireEvent('check', this, state);
85         }
86         
87         this.parent().validate();
88     }
89     
90 });
91  
92
93