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