jsakalos
8 Feb 2009, 10:38 PM
Hi all,
sometimes we want to populate combo's store with some records before we actually call setValue. I've created a very simple extension for that.
How it works?
PopCombo's setValue method accept also object as argument, for example
var o = {value:1,records:[[0,'Item 1'],[1,'Item 2']]};
If such object is passed to setValue method, combo's store is first loaded with "records" member of passed object and then value is set to "value" member.
Demo: http://examples.extjs.eu/?ex=popcombo
Ext.ux.form.PopCombo source:
// vim: ts=4:sw=4:nu:fdc=4:nospell
/*global Ext */
/**
* @class Ext.ux.form.PopCombo
* @extends Ext.form.ComboBox
*
* Pop(ulating)Combo's setValue method accepts object as argument and implements
* special processing of the object. For example:
* <pre>
* var combo = new Ext.ux.form.PopCombo();
* var o = {value:1,records:[[0,'Item 1'],[1,'Item 2']]};
* combo.setValue(o);
* </pre>
* If records are found in the passed object the combo store is popupated with
* these records before the value is actually set.
*
* @author Ing. Jozef Sakáloš
* @copyright (c) 2009, by Ing. Jozef Sakáloš
* @date 9. February 2009
* @version 0.1
* @revision $Id: Ext.ux.form.PopCombo.js 553 2009-02-09 08:49:22Z jozo $
*
* @license Ext.ux.form.PopCombo.js is licensed under the terms of the Open Source
* LGPL 3.0 license. Commercial use is permitted to the extent that the
* code/component(s) do NOT become part of another Open Source or Commercially
* licensed development library or toolkit without explicit permission.
*
* <p>License details: <a href="http://www.gnu.org/licenses/lgpl.html"
* target="_blank">http://www.gnu.org/licenses/lgpl.html</a></p>
*
* @forum 59406
*/
// create namespace
Ext.ns('Ext.ux.form');
/**
* Creates new Ext.ux.form.PopCombo
* @constructor
* @param {Object} config A config object
*/
Ext.ux.form.PopCombo = Ext.extend(Ext.form.ComboBox, {
// defaults
/**
* @cfg {Object} paramNames
* Defines names that are used for "value" and "records" members
* (defaults to {value:"value", records:"records"})
*/
paramNames:{value:'value', records:'records'}
,setValue:function(value) {
var val = value;
if('object' === typeof value && '[object Object]' === Object.prototype.toString.call(value)) {
if(undefined !== value[this.paramNames['records']]) {
this.store.loadData(value[this.paramNames['records']]);
}
val = value[this.paramNames['value']];
}
Ext.ux.form.PopCombo.superclass.setValue.call(this, val);
} // eo function setValue
}); // eo extend
// register xtype
Ext.reg('popcombo', Ext.ux.form.PopCombo);
// eof
sometimes we want to populate combo's store with some records before we actually call setValue. I've created a very simple extension for that.
How it works?
PopCombo's setValue method accept also object as argument, for example
var o = {value:1,records:[[0,'Item 1'],[1,'Item 2']]};
If such object is passed to setValue method, combo's store is first loaded with "records" member of passed object and then value is set to "value" member.
Demo: http://examples.extjs.eu/?ex=popcombo
Ext.ux.form.PopCombo source:
// vim: ts=4:sw=4:nu:fdc=4:nospell
/*global Ext */
/**
* @class Ext.ux.form.PopCombo
* @extends Ext.form.ComboBox
*
* Pop(ulating)Combo's setValue method accepts object as argument and implements
* special processing of the object. For example:
* <pre>
* var combo = new Ext.ux.form.PopCombo();
* var o = {value:1,records:[[0,'Item 1'],[1,'Item 2']]};
* combo.setValue(o);
* </pre>
* If records are found in the passed object the combo store is popupated with
* these records before the value is actually set.
*
* @author Ing. Jozef Sakáloš
* @copyright (c) 2009, by Ing. Jozef Sakáloš
* @date 9. February 2009
* @version 0.1
* @revision $Id: Ext.ux.form.PopCombo.js 553 2009-02-09 08:49:22Z jozo $
*
* @license Ext.ux.form.PopCombo.js is licensed under the terms of the Open Source
* LGPL 3.0 license. Commercial use is permitted to the extent that the
* code/component(s) do NOT become part of another Open Source or Commercially
* licensed development library or toolkit without explicit permission.
*
* <p>License details: <a href="http://www.gnu.org/licenses/lgpl.html"
* target="_blank">http://www.gnu.org/licenses/lgpl.html</a></p>
*
* @forum 59406
*/
// create namespace
Ext.ns('Ext.ux.form');
/**
* Creates new Ext.ux.form.PopCombo
* @constructor
* @param {Object} config A config object
*/
Ext.ux.form.PopCombo = Ext.extend(Ext.form.ComboBox, {
// defaults
/**
* @cfg {Object} paramNames
* Defines names that are used for "value" and "records" members
* (defaults to {value:"value", records:"records"})
*/
paramNames:{value:'value', records:'records'}
,setValue:function(value) {
var val = value;
if('object' === typeof value && '[object Object]' === Object.prototype.toString.call(value)) {
if(undefined !== value[this.paramNames['records']]) {
this.store.loadData(value[this.paramNames['records']]);
}
val = value[this.paramNames['value']];
}
Ext.ux.form.PopCombo.superclass.setValue.call(this, val);
} // eo function setValue
}); // eo extend
// register xtype
Ext.reg('popcombo', Ext.ux.form.PopCombo);
// eof