10 * @class Roo.bootstrap.RadioSet
11 * @extends Roo.bootstrap.Input
12 * Bootstrap RadioSet class
13 * @cfg {String} indicatorpos (left|right) default left
14 * @cfg {Boolean} inline (true|false) inline the element (default true)
15 * @cfg {String} weight (primary|warning|info|danger|success) The text that appears beside the radio
17 * Create a new RadioSet
18 * @param {Object} config The config object
21 Roo.bootstrap.RadioSet = function(config){
23 Roo.bootstrap.RadioSet.superclass.constructor.call(this, config);
27 Roo.bootstrap.RadioSet.register(this);
32 * Fires when the element is checked or unchecked.
33 * @param {Roo.bootstrap.RadioSet} this This radio
34 * @param {Roo.bootstrap.Radio} item The checked item
41 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input, {
51 indicatorpos : 'left',
58 getAutoCreate : function()
62 cls : 'roo-radio-set-label',
66 html : this.fieldLabel
71 if(this.indicatorpos == 'left'){
74 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
75 tooltip : 'This field is required'
80 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
81 tooltip : 'This field is required'
87 cls : 'roo-radio-set-items'
90 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
92 if (align === 'left' && this.fieldLabel.length) {
95 cls : "roo-radio-set-right",
101 if(this.labelWidth > 12){
102 label.style = "width: " + this.labelWidth + 'px';
105 if(this.labelWidth < 13 && this.labelmd == 0){
106 this.labelmd = this.labelWidth;
109 if(this.labellg > 0){
110 label.cls += ' col-lg-' + this.labellg;
111 items.cls += ' col-lg-' + (12 - this.labellg);
114 if(this.labelmd > 0){
115 label.cls += ' col-md-' + this.labelmd;
116 items.cls += ' col-md-' + (12 - this.labelmd);
119 if(this.labelsm > 0){
120 label.cls += ' col-sm-' + this.labelsm;
121 items.cls += ' col-sm-' + (12 - this.labelsm);
124 if(this.labelxs > 0){
125 label.cls += ' col-xs-' + this.labelxs;
126 items.cls += ' col-xs-' + (12 - this.labelxs);
132 cls : 'roo-radio-set',
136 cls : 'roo-radio-set-input',
139 value : this.value ? this.value : ''
146 if(this.weight.length){
147 cfg.cls += ' roo-radio-' + this.weight;
151 cfg.cls += ' roo-radio-set-inline';
158 initEvents : function()
160 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
161 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
163 if(!this.fieldLabel.length){
167 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
168 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
170 this.indicatorEl().setVisibilityMode(Roo.Element.DISPLAY);
171 this.indicatorEl().hide();
173 this.originalValue = this.getValue();
179 return this.el.select('.roo-radio-set-input', true).first();
182 getChildContainer : function()
187 register : function(item)
189 this.radioes.push(item);
193 validate : function()
197 Roo.each(this.radioes, function(i){
206 if(this.disabled || this.allowBlank || valid){
216 markValid : function()
218 if(this.labelEl.isVisible(true)){
219 this.indicatorEl().hide();
222 this.el.removeClass([this.invalidClass, this.validClass]);
223 this.el.addClass(this.validClass);
225 this.fireEvent('valid', this);
228 markInvalid : function(msg)
230 if(this.allowBlank || this.disabled){
234 if(this.labelEl.isVisible(true)){
235 this.indicatorEl().show();
238 this.el.removeClass([this.invalidClass, this.validClass]);
239 this.el.addClass(this.invalidClass);
241 this.fireEvent('invalid', this, msg);
245 setValue : function(v, suppressEvent)
247 Roo.each(this.radioes, function(i){
250 i.el.removeClass('checked');
252 if(i.value === v || i.value.toString() === v.toString()){
254 i.el.addClass('checked');
256 if(suppressEvent !== true){
257 this.fireEvent('check', this, i);
263 Roo.bootstrap.RadioSet.superclass.setValue.call(this, v);
267 clearInvalid : function(){
269 if(!this.el || this.preventMark){
273 if(this.labelEl.isVisible(true)){
274 this.indicatorEl().hide();
277 this.el.removeClass([this.invalidClass]);
279 this.fireEvent('valid', this);
284 Roo.apply(Roo.bootstrap.RadioSet, {
288 register : function(set)
290 this.groups[set.name] = set;
295 if (typeof(this.groups[name]) == 'undefined') {
299 return this.groups[name] ;