0

I am using extJs 6. I have code like below, it can be a text box or anything else also. I want to make a common repo for all the fields and then include in the reports by using xtype or something else, because same code will be used in multiple reports.

  items: [
                {
                    xtype: 'combo',
                    fieldLabel: 'year',
                    name: 'Year',
                    displayField: 'Key',
                    valueField: 'Year',
                    value: new Date().getFullYear(),
                    store: {
                        type: 'years'
                    }
                },

It should look like

   items: [
                    {
                        xtype: 'yearfield'
                    },
          ]

or

  items: [
                            xtype: 'yearfield'
              ]

As what should i define these fields and what should it extend.

Hacker
  • 7,798
  • 19
  • 84
  • 154

1 Answers1

3

Since your old field is of xtype:'combo', it is a Ext.form.field.ComboBox, so you would have to extend that.

Ext.define('MyApp.view.MyOwnYearField',{
    extend:'Ext.form.field.ComboBox',
    xtype:'yearfield', // <- the xtype of MyOwnYearField is defined here
    fieldLabel: 'year',
    name: 'Year',
    displayField: 'Key',
    valueField: 'Year',
    value: new Date().getFullYear(),
    store: {
        type: 'years'
    }
});

Before you can use xtype:'yearfield', you have to load the file where it is in, e.g. by adding the full name to the requires list:

Ext.define('MyApp.view.SomeReport',{
    requires:[
        'MyApp.view.MyOwnYearField' // The class is loaded here
    ],
    items:[{
        xtype:'yearfield' // The class is referenced by xtype. 
                          // This is only possible after it has been loaded!
    }]
Alexander
  • 19,906
  • 19
  • 75
  • 162
  • So in this case if i have 20 fields are there, then in requires i need 20 entries? or is it 1 file entry.. – Hacker Jun 15 '16 at 10:29
  • If you have to keep your code standard-compliant, I fear that you will need 20 entries. If you don't have to, however, you can put all your field definitions into a single file. In that case, you only need one entry, referencing that file. – Alexander Jun 15 '16 at 10:35
  • If i create this xtype, if i use the same xtype is 2 or more reports, does it create a new object or is it a singleton. I am using tab panel. – Hacker Jun 15 '16 at 11:33