PDA

View Full Version : Defining combo in separate class



jpcook01
6 Sep 2011, 7:47 AM
Hi,

I have defined a combo in a separate class as follows:


/*
* A combo box for selecting different sitemaps
* @author cookj02
*/
Ext.define('NavBuilder.SitemapComboBox', {
extend: 'Ext.form.field.ComboBox',
alias: 'widget.sitemapcombo',

initComponent: function(){
Ext.apply(this, {
mode: 'local',
value: 'Standard',
triggerAction: 'all',
forceSelection: true,
editable: false,
fieldLabel: 'Sitemap',
labelWidth: 50,
width: 270,
name: 'selectsitemapcombo',
itemId: 'selectsitemapcombo',
displayField: 'uri',
valueField: 'uri',
store: Ext.create('Ext.data.Store', {
model: 'NavBuilder.SitemapItem',
proxy: {
type: 'ajax',
url: 'sitemap/list'
},
autoLoad: true,
listeners: {
load: function(store, records, successful, operation, eOpts ){
//some action
//sitemapcombo.setValue(store.getAt(0).get('uri'));
}
}

})

});
this.callParent();
}
});



But when I reference it from another class eg)



tems: [{
xtype: 'sitemapcombo'
}, {
xtype: 'tbseparator'
}, {.....


I get the following error: namespace is undefined

It is fine inline. Probably something silly.

Jon

arthurakay
6 Sep 2011, 10:25 AM
You need to "require" your new class so that it gets loaded!



Ext.define('foobar.class', {
requires: [ 'NacBuilder.SitemapComboBox' ],
...
items : [ { xtype: 'sitemapcombo' } ],
...
});

jpcook01
7 Sep 2011, 12:47 AM
So now I get the following error with:



Ext.define('NavBuilder.SitemapList', {
requires: [ 'NavBuilder.SitemapComboBox' ],


uncaught exception: Ext.Loader is not enabled, so dependencies cannot be resolved dynamically. Missing required class: NavBuilder.SitemapComboBox Line 0

But I have the loader enabled, this is my entry point:



<script type="text/javascript">
Ext.require([
'Ext.tree.*',
'Ext.data.*',
'Ext.tip.*',
]);
Ext.onReady(function(){
Ext.Loader.setConfig({enabled:true});
Ext.QuickTips.init();
new NavBuilder.Main();
});
</script>


I tried putting the class in the Ext require block as well but that results in the same error as well.

Jon

arthurakay
7 Sep 2011, 8:19 AM
Do you ever set the paths for your Loader config? See the "paths" config on Loader.

My guess is that you aren't telling Ext.Loader where to find your "NavBuilder" namespace classes.

Also, this line should be outside the onReady() block so that it gets run immediately... put it above your Ext.requires() statement.


Ext.Loader.setConfig({ enabled: true })