X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/c930e9176a5a85509c5b0230e2bff5c22a591432..c8256059947f3aa8f5b0a9a2acf55e2142bb4742:/src/widgets/form/CheckboxGroup.js?ds=sidebyside diff --git a/src/widgets/form/CheckboxGroup.js b/src/widgets/form/CheckboxGroup.js index ee344076..e925d708 100644 --- a/src/widgets/form/CheckboxGroup.js +++ b/src/widgets/form/CheckboxGroup.js @@ -1,6 +1,6 @@ /*! - * Ext JS Library 3.0.0 - * Copyright(c) 2006-2009 Ext JS, LLC + * Ext JS Library 3.2.1 + * Copyright(c) 2006-2010 Ext JS, Inc. * licensing@extjs.com * http://www.extjs.com/license */ @@ -39,7 +39,7 @@ Ext.form.CheckboxGroup = Ext.extend(Ext.form.Field, { * checkbox/radio controls using automatic layout. This config can take several types of values: *
The controls will be rendered one per column on one row and the width * of each column will be evenly distributed based on the width of the overall field container. This is the default.
If you specific a number (e.g., 3) that number of columns will be + *
If you specific a number (e.g., 3) that number of columns will be * created and the contained controls will be automatically distributed based on the value of {@link #vertical}.
You can also specify an array of column widths, mixing integer
* (fixed width) and float (percentage width) values as needed (e.g., [100, .25, .75]). Any integer values will
@@ -49,7 +49,7 @@ Ext.form.CheckboxGroup = Ext.extend(Ext.form.Field, {
*/
columns : 'auto',
/**
- * @cfg {Boolean} vertical True to distribute contained controls across columns, completely filling each column
+ * @cfg {Boolean} vertical True to distribute contained controls across columns, completely filling each column
* top to bottom before starting on the next column. The number of controls in each column will be automatically
* calculated to keep columns as even as possible. The default value is false, so that controls will be added
* to columns one at a time, completely filling each row left to right before starting on the next row.
@@ -61,17 +61,17 @@ Ext.form.CheckboxGroup = Ext.extend(Ext.form.Field, {
*/
allowBlank : true,
/**
- * @cfg {String} blankText Error text to display if the {@link #allowBlank} validation fails (defaults to "You must
+ * @cfg {String} blankText Error text to display if the {@link #allowBlank} validation fails (defaults to "You must
* select at least one item in this group")
*/
blankText : "You must select at least one item in this group",
-
+
// private
defaultType : 'checkbox',
-
+
// private
groupCls : 'x-form-check-group',
-
+
// private
initComponent: function(){
this.addEvents(
@@ -82,33 +82,37 @@ Ext.form.CheckboxGroup = Ext.extend(Ext.form.Field, {
* @param {Array} checked An array containing the checked boxes.
*/
'change'
- );
+ );
+ this.on('change', this.validate, this);
Ext.form.CheckboxGroup.superclass.initComponent.call(this);
},
-
+
// private
onRender : function(ct, position){
if(!this.el){
var panelCfg = {
+ autoEl: {
+ id: this.id
+ },
cls: this.groupCls,
layout: 'column',
- border: false,
- renderTo: ct
+ renderTo: ct,
+ bufferResize: false // Default this to false, since it doesn't really have a proper ownerCt.
};
var colCfg = {
+ xtype: 'container',
defaultType: this.defaultType,
layout: 'form',
- border: false,
defaults: {
hideLabel: true,
anchor: '100%'
}
};
-
+
if(this.items[0].items){
-
+
// The container has standard ColumnLayout configs, so pass them in directly
-
+
Ext.apply(panelCfg, {
layoutConfig: {columns: this.items.length},
defaults: this.defaults,
@@ -117,14 +121,14 @@ Ext.form.CheckboxGroup = Ext.extend(Ext.form.Field, {
for(var i=0, len=this.items.length; i
// call with name and value
myCheckboxGroup.setValue('cb-col-1', true);
-// call with an array of boolean values
+// call with an array of boolean values
myCheckboxGroup.setValue([true, false, false]);
// call with an object literal specifying item:value pairs
myCheckboxGroup.setValue({
@@ -305,47 +359,71 @@ myCheckboxGroup.setValue('cb-col-1,cb-col-3');
* @param {Boolean} value (optional) The value to set the item.
* @return {Ext.form.CheckboxGroup} this
*/
- setValue : function(id, value){
+ setValue: function(){
if(this.rendered){
- if(arguments.length == 1){
- if(Ext.isArray(id)){
- //an array of boolean values
- Ext.each(id, function(val, idx){
+ this.onSetValue.apply(this, arguments);
+ }else{
+ this.buffered = true;
+ this.value = arguments;
+ }
+ return this;
+ },
+
+ /**
+ * @private
+ * Sets the values of one or more of the items within the CheckboxGroup
+ * @param {String|Array|Object} id Can take multiple forms. Can be optionally:
+ *
+ *
+ * @param {String} value The value to set the field to if the first argument was a string
+ */
+ onSetValue: function(id, value){
+ if(arguments.length == 1){
+ if(Ext.isArray(id)){
+ Ext.each(id, function(val, idx){
+ if (Ext.isObject(val) && val.setValue){ // array of checkbox components to be checked
+ val.setValue(true);
+ if (this.resetOriginal === true) {
+ val.originalValue = val.getValue();
+ }
+ } else { // an array of boolean values
var item = this.items.itemAt(idx);
if(item){
item.setValue(val);
}
- }, this);
- }else if(Ext.isObject(id)){
- //set of name/value pairs
- for(var i in id){
- var f = this.getBox(i);
- if(f){
- f.setValue(id[i]);
- }
}
- }else{
- this.setValueForItem(id);
+ }, this);
+ }else if(Ext.isObject(id)){
+ // set of name/value pairs
+ for(var i in id){
+ var f = this.getBox(i);
+ if(f){
+ f.setValue(id[i]);
+ }
}
}else{
- var f = this.getBox(id);
- if(f){
- f.setValue(value);
- }
+ this.setValueForItem(id);
}
}else{
- this.values = arguments;
+ var f = this.getBox(id);
+ if(f){
+ f.setValue(value);
+ }
}
- return this;
},
-
+
// private
- onDestroy: function(){
+ beforeDestroy: function(){
Ext.destroy(this.panel);
- Ext.form.CheckboxGroup.superclass.onDestroy.call(this);
+ Ext.form.CheckboxGroup.superclass.beforeDestroy.call(this);
},
-
+
setValueForItem : function(val){
val = String(val).split(',');
this.eachItem(function(item){
@@ -354,7 +432,7 @@ myCheckboxGroup.setValue('cb-col-1,cb-col-3');
}
});
},
-
+
// private
getBox : function(id){
var box = null;
@@ -366,7 +444,7 @@ myCheckboxGroup.setValue('cb-col-1,cb-col-3');
});
return box;
},
-
+
/**
* Gets an array of the selected {@link Ext.form.Checkbox} in the group.
* @return {Array} An array of the selected checkboxes.
@@ -380,40 +458,36 @@ myCheckboxGroup.setValue('cb-col-1,cb-col-3');
});
return out;
},
-
- // private
- eachItem: function(fn){
+
+ /**
+ * @private
+ * Convenience function which passes the given function to every item in the composite
+ * @param {Function} fn The function to call
+ * @param {Object} scope Optional scope object
+ */
+ eachItem: function(fn, scope) {
if(this.items && this.items.each){
- this.items.each(fn, this);
+ this.items.each(fn, scope || this);
}
},
-
+
/**
* @cfg {String} name
* @hide
*/
- /**
- * @method initValue
- * @hide
- */
- initValue : Ext.emptyFn,
- /**
- * @method getValue
- * @hide
- */
- getValue : Ext.emptyFn,
+
/**
* @method getRawValue
* @hide
*/
getRawValue : Ext.emptyFn,
-
+
/**
* @method setRawValue
* @hide
*/
setRawValue : Ext.emptyFn
-
+
});
Ext.reg('checkboxgroup', Ext.form.CheckboxGroup);