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
39 * Fires when the element is click.
40 * @param {Roo.bootstrap.RadioSet} this This radio set
41 * @param {Roo.bootstrap.Radio} item The checked item
42 * @param {Roo.EventObject} e The event object
49 Roo.extend(Roo.bootstrap.RadioSet, Roo.bootstrap.Input, {
57 indicatorpos : 'left',
59 getAutoCreate : function()
63 cls : 'roo-radio-set-label',
67 html : this.fieldLabel
71 if (Roo.bootstrap.version == 3) {
74 if(this.indicatorpos == 'left'){
77 cls : 'roo-required-indicator left-indicator text-danger fa fa-lg fa-star',
78 tooltip : 'This field is required'
83 cls : 'roo-required-indicator right-indicator text-danger fa fa-lg fa-star',
84 tooltip : 'This field is required'
90 cls : 'roo-radio-set-items'
93 var align = (!this.labelAlign) ? this.parentLabelAlign() : this.labelAlign;
95 if (align === 'left' && this.fieldLabel.length) {
98 cls : "roo-radio-set-right",
104 if(this.labelWidth > 12){
105 label.style = "width: " + this.labelWidth + 'px';
108 if(this.labelWidth < 13 && this.labelmd == 0){
109 this.labelmd = this.labelWidth;
112 if(this.labellg > 0){
113 label.cls += ' col-lg-' + this.labellg;
114 items.cls += ' col-lg-' + (12 - this.labellg);
117 if(this.labelmd > 0){
118 label.cls += ' col-md-' + this.labelmd;
119 items.cls += ' col-md-' + (12 - this.labelmd);
122 if(this.labelsm > 0){
123 label.cls += ' col-sm-' + this.labelsm;
124 items.cls += ' col-sm-' + (12 - this.labelsm);
127 if(this.labelxs > 0){
128 label.cls += ' col-xs-' + this.labelxs;
129 items.cls += ' col-xs-' + (12 - this.labelxs);
135 cls : 'roo-radio-set',
139 cls : 'roo-radio-set-input',
142 value : this.value ? this.value : ''
149 if(this.weight.length){
150 cfg.cls += ' roo-radio-' + this.weight;
154 cfg.cls += ' roo-radio-set-inline';
158 ['xs','sm','md','lg'].map(function(size){
159 if (settings[size]) {
160 cfg.cls += ' col-' + size + '-' + settings[size];
168 initEvents : function()
170 this.labelEl = this.el.select('.roo-radio-set-label', true).first();
171 this.labelEl.setVisibilityMode(Roo.Element.DISPLAY);
173 if(!this.fieldLabel.length){
177 this.itemsEl = this.el.select('.roo-radio-set-items', true).first();
178 this.itemsEl.setVisibilityMode(Roo.Element.DISPLAY);
180 this.indicator = this.indicatorEl();
183 this.indicator.addClass('invisible');
186 this.originalValue = this.getValue();
192 return this.el.select('.roo-radio-set-input', true).first();
195 getChildContainer : function()
200 register : function(item)
202 this.radioes.push(item);
206 validate : function()
208 if(this.getVisibilityEl().hasClass('hidden')){
214 Roo.each(this.radioes, function(i){
223 if(this.allowBlank) {
227 if(this.disabled || valid){
237 markValid : function()
239 if(this.labelEl.isVisible(true) && this.indicatorEl()){
240 this.indicatorEl().removeClass('visible');
241 this.indicatorEl().addClass('invisible');
245 if (Roo.bootstrap.version == 3) {
246 this.el.removeClass([this.invalidClass, this.validClass]);
247 this.el.addClass(this.validClass);
249 this.el.removeClass(['is-invalid','is-valid']);
250 this.el.addClass(['is-valid']);
252 this.fireEvent('valid', this);
255 markInvalid : function(msg)
257 if(this.allowBlank || this.disabled){
261 if(this.labelEl.isVisible(true) && this.indicatorEl()){
262 this.indicatorEl().removeClass('invisible');
263 this.indicatorEl().addClass('visible');
265 if (Roo.bootstrap.version == 3) {
266 this.el.removeClass([this.invalidClass, this.validClass]);
267 this.el.addClass(this.invalidClass);
269 this.el.removeClass(['is-invalid','is-valid']);
270 this.el.addClass(['is-invalid']);
273 this.fireEvent('invalid', this, msg);
277 setValue : function(v, suppressEvent)
279 if(this.value === v){
286 this.inputEl().dom.value = (v === null || v === undefined ? '' : v);
289 Roo.each(this.radioes, function(i){
291 i.el.removeClass('checked');
294 Roo.each(this.radioes, function(i){
296 if(i.value === v || i.value.toString() === v.toString()){
298 i.el.addClass('checked');
300 if(suppressEvent !== true){
301 this.fireEvent('check', this, i);
312 clearInvalid : function(){
314 if(!this.el || this.preventMark){
318 this.el.removeClass([this.invalidClass]);
320 this.fireEvent('valid', this);
325 Roo.apply(Roo.bootstrap.RadioSet, {
329 register : function(set)
331 this.groups[set.name] = set;
336 if (typeof(this.groups[name]) == 'undefined') {
340 return this.groups[name] ;