View Full Version : Custom component that could represent multiple different form field components

4 Jun 2013, 6:13 AM
My app allows for various different entities to have custom fields. Those fields can be defined by the user, they can be set to be a date, combo, text, etc. I'd like to abstract a custom field into it's own component, but not sure how I can make a component that would render a different type of component based on config options given to it. So basically, I'd want to use my fields like this:

this.items = [
{ xtype: 'customfield', type: 'date', name: 'customField1' },
{ xtype: 'customfield', type: 'combo', name: 'customField2' },
{ xtype: 'customfield', type: 'text', name: 'customField3' }

Given that I can't extend all the different fields, I'm not sure how I can accomplish this. Or do I need to work outside of the Ext JS class system and just add things to this.prototype? Or something along those lines? I do realize I could just make some kind of singleton class that would return what I wanted using a function and some arguments, but having an actual component seems like a cleaner way of doing things if it's possible.

6 Jun 2013, 9:45 AM
The way I ended up going about it is defining my custom component as a FieldContainer and then populating that with the field that I needed. Not exactly what I wanted, but got the job done.