3
* Copyright(c) 2006-2008, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.form.CheckboxGroup
11
* @extends Ext.form.Field
12
* A grouping container for {@link Ext.form.Checkbox} controls.
14
* Creates a new CheckboxGroup
15
* @param {Object} config Configuration options
17
Ext.form.CheckboxGroup = Ext.extend(Ext.form.Field, {
19
* @cfg {String/Number/Array} columns Specifies the number of columns to use when displaying grouped
20
* checkbox/radio controls using automatic layout. This config can take several types of values:
21
* <ul><li><b>'auto'</b> : <p class="sub-desc">The controls will be rendered one per column on one row and the width
22
* of each column will be evenly distributed based on the width of the overall field container. This is the default.</p></li>
23
* <li><b>Number</b> : <p class="sub-desc">If you specific a number (e.g., 3) that number of columns will be
24
* created and the contained controls will be automatically distributed based on the value of {@link #vertical}.</p></li>
25
* <li><b>Array</b> : Object<p class="sub-desc">You can also specify an array of column widths, mixing integer
26
* (fixed width) and float (percentage width) values as needed (e.g., [100, .25, .75]). Any integer values will
27
* be rendered first, then any float values will be calculated as a percentage of the remaining space. Float
28
* values do not have to add up to 1 (100%) although if you want the controls to take up the entire field
29
* container you should do so.</p></li></ul>
33
* @cfg {Boolean} vertical True to distribute contained controls across columns, completely filling each column
34
* top to bottom before starting on the next column. The number of controls in each column will be automatically
35
* calculated to keep columns as even as possible. The default value is false, so that controls will be added
36
* to columns one at a time, completely filling each row left to right before starting on the next row.
40
* @cfg {Boolean} allowBlank False to validate that at least one item in the group is checked (defaults to true).
41
* If no items are selected at validation time, {@link @blankText} will be used as the error text.
45
* @cfg {String} blankText Error text to display if the {@link #allowBlank} validation fails (defaults to "You must
46
* select at least one item in this group")
48
blankText : "You must select at least one item in this group",
51
defaultType : 'checkbox',
54
groupCls: 'x-form-check-group',
57
onRender : function(ct, position){
66
defaultType: this.defaultType,
75
if(this.items[0].items){
77
// The container has standard ColumnLayout configs, so pass them in directly
80
layoutConfig: {columns: this.items.length},
81
defaults: this.defaults,
84
for(var i=0, len=this.items.length; i<len; i++){
85
Ext.applyIf(this.items[i], colCfg);
90
// The container has field item configs, so we have to generate the column
91
// panels first then move the items into the columns as needed.
93
var numCols, cols = [];
95
if(typeof this.columns == 'string'){ // 'auto' so create a col per item
96
this.columns = this.items.length;
98
if(!Ext.isArray(this.columns)){
100
for(var i=0; i<this.columns; i++){
101
cs.push((100/this.columns)*.01); // distribute by even %
106
numCols = this.columns.length;
108
// Generate the column configs with the correct width setting
109
for(var i=0; i<numCols; i++){
110
var cc = Ext.apply({items:[]}, colCfg);
111
cc[this.columns[i] <= 1 ? 'columnWidth' : 'width'] = this.columns[i];
113
cc.defaults = Ext.apply(cc.defaults || {}, this.defaults)
118
// Distribute the original items into the columns
120
var rows = Math.ceil(this.items.length / numCols), ri = 0;
121
for(var i=0, len=this.items.length; i<len; i++){
122
if(i>0 && i%rows==0){
125
if(this.items[i].fieldLabel){
126
this.items[i].hideLabel = false;
128
cols[ri].items.push(this.items[i]);
131
for(var i=0, len=this.items.length; i<len; i++){
132
var ci = i % numCols;
133
if(this.items[i].fieldLabel){
134
this.items[i].hideLabel = false;
136
cols[ci].items.push(this.items[i]);
140
Ext.apply(panelCfg, {
141
layoutConfig: {columns: numCols},
146
this.panel = new Ext.Panel(panelCfg);
147
this.el = this.panel.getEl();
149
if(this.forId && this.itemCls){
150
var l = this.el.up(this.itemCls).child('label', true);
152
l.setAttribute('htmlFor', this.forId);
156
var fields = this.panel.findBy(function(c){
157
return c.isFormField;
160
this.items = new Ext.util.MixedCollection();
161
this.items.addAll(fields);
163
Ext.form.CheckboxGroup.superclass.onRender.call(this, ct, position);
167
validateValue : function(value){
168
if(!this.allowBlank){
170
this.items.each(function(f){
172
return blank = false;
176
this.markInvalid(this.blankText);
184
onDisable : function(){
185
this.items.each(function(item){
191
onEnable : function(){
192
this.items.each(function(item){
198
onResize : function(w, h){
199
this.panel.setSize(w, h);
200
this.panel.doLayout();
203
// inherit docs from Field
205
Ext.form.CheckboxGroup.superclass.reset.call(this);
206
this.items.each(function(c){
221
initValue : Ext.emptyFn,
226
getValue : Ext.emptyFn,
228
* @method getRawValue
231
getRawValue : Ext.emptyFn,
236
setValue : Ext.emptyFn,
238
* @method setRawValue
241
setRawValue : Ext.emptyFn
245
Ext.reg('checkboxgroup', Ext.form.CheckboxGroup);