In my CMP’s create and update forms, I’d like to display a list of checkboxes corresponding to ModX resources.
To display the right checkboxes, I believe I need to follow roughly this process:
- Create a processor to return the relevant Resources as JSON.
- Retrieve that data in an ExtJS JsonStore.
- Pass it to the items parameter of my checkboxgroup on instantiation.
I’m new to all this ExtJS stuff, and I’m having a lot of trouble structuring code. My Window object looks like this:
Shepherd.window.CreateArticle = function(config) {
config = config || {};
Ext.applyIf(config,{
title: _('shepherd.article_create')
,url: Shepherd.config.connectorUrl
,baseParams: { action: 'mgr/article/create' }
,width: 900
,fields:
[{ xtype: 'textfield'
,fieldLabel: _('shepherd.article_title')
,name: 'title'
,width: 300
},{
xtype: 'tinymce'
,tinymceSettings: {
theme : "advanced",
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|"
...snip...
}
,fieldLabel: _('shepherd.article_content')
,name: 'content'
,id: 'shepherd-article-content'
,width: 700
},{
xtype: 'shepherd-combo-authors'
,fieldLabel: 'Author'
}
]
});
Shepherd.window.CreateArticle.superclass.constructor.call(this,config);
};
Ext.extend(Shepherd.window.CreateArticle, MODx.Window);
Ext.reg('shepherd-window-article-create', Shepherd.window.CreateArticle);
I managed to get a dynamic dropdown working along similar lines by creating the field like this:
Shepherd.combo.Authors = function(config) {
config = config || {};
Ext.applyIf(config,{
id: 'shepherd-combo-authors'
,name: 'author'
,displayField: 'pagetitle'
,valueField: 'id'
,fields: ['id','pagetitle']
,url: Shepherd.config.connectorUrl
,baseParams: { action: 'mgr/article/getAuthorList' }
});
Shepherd.combo.Authors.superclass.constructor.call(this,config);
};
Ext.extend(Shepherd.combo.Authors, MODx.combo.ComboBox);
Ext.reg('shepherd-combo-authors', Shepherd.combo.Authors);
Unfortunately checkboxgroups seem to be very different animals. I tried dumping this in an onReady (using the same processor as before for now):
var store = new Ext.data.JsonStore({
url: Shepherd.config.connectorUrl
,baseParams: { action: 'mgr/article/getAuthorList' }
,fields: ['id', 'pagetitle']
,autoLoad: true
});
That seems to be working OK, although I’d rather be loading it when the Window is opened. Using the store in the checkboxgroup is what I can’t get right:
{ xtype: 'checkboxgroup' ,items: store }
When I open my create form, "this.items[0] is undefined" pops up in the console. I can get "h.prototype is undefined" instead with...
{ xtype: 'checkboxgroup' ,items: new Ext.data.JsonReader({ root: 'results' }, store) }
Any pointers?