|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
Announcements
Services
Chapters
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
IntroductionExtJS is a really cool Javascript library that contains great form building components. But, like all things you start using it in anger and it isn't long before you find something it can't do out-of-the-box and you want to extend it. I had a form made up of standard Ext.form components but then I wanted to output a couple of DIVs in the amongst the other form elements so that I could render some special content to them. Specifically, I had a report that is broken into sections and each can have files attached to it. I wanted to display a button to bring up a file upload dialog and a list of uploaded files. For interest the file upload dialog I used can be found here So it was that I needed to develop an extension to the Ext.component class that could render out my divs. This is quite simple but it took a fair bit of investigation and hunting through the source to find out what was required so I thought I should create a little demo component and put an aritcle here to save others some time. If you are looking to specialise and existing component there is a great example hereUsing the codeBasically, you need three things to make it work (you may even need less but I implemented these three and then I was happy): Note the first list that registers a name space and the last line that registers the control with a unique All the good stuff happens in Ext.namespace('Ext.ensigma');
Ext.ensigma.DemoComponent = Ext.extend(Ext.Component, {
initComponent : function(){
Ext.ensigma.DemoComponent.superclass.initComponent.call(this);
},
// private
onRender : function(ct, position){
if(!this.template){
if(!Ext.ensigma.DemoComponent.filesetTemplate){
Ext.ensigma.DemoComponent.filesetTemplate = new Ext.Template(
'<div><div>{0}</div><div>{1}</div></div>'
);
}
this.template = Ext.ensigma.DemoComponent.filesetTemplate;
}
var fs, targs = [this.text1 || ' ', this.text2 || ' '];
if(position){
fs = this.template.insertBefore(position, targs, true);
}else{
fs = this.template.append(ct, targs, true);
}
},
// private
afterRender : function(){
Ext.ensigma.DemoComponent.superclass.afterRender.call(this);
}
});
Ext.reg('fileset', Ext.ensigma.DemoComponent);
Here is the example code that uses the component: Ext.onReady(function(){
Ext.QuickTips.init();
var simple = new Ext.FormPanel({
labelWidth: 75,
frame:true,
title: 'Fileset Form',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 230},
defaultType: 'textfield',
items: [new Ext.form.TextField ({
fieldLabel: 'First Name',
name: 'first',
allowBlank:false
}), new Ext.ensigma.DemoComponent ({
text1: 'hello world',
text2: 'goodbye cruel world',
autoWidth: true
}),
]
});
simple.render(document.body);
});
History
|
|||||||||||||||||||||||||||||||||||||||