PDA

View Full Version : Subclass inherance and event listeners



pmaisonn
2 Dec 2011, 8:06 AM
I've defined into Ext Designer a custom subclass of Panel, ClientAddPanel, that contains a form and a submit button which calls a saveClient method on click.


At application launch, I can corrreclty see into the console the initComponent method call.

The issue is when I try to instantiate a second time my subclass panel which is linked to a new tab, the initComponent method is not called so I'm loosing the default event handling for this subclass.

Where did I miss the bus ? :)

thanks for your support,


Here is the code for my subclass :


Ext.define('MyApp.view.ClientAddPanel', {
extend: 'MyApp.view.ui.ClientAddPanel',
alias: 'widget.clientaddpnl',


initComponent: function() {
console.log('ClientSearchPanel::initComponent: start');
this.callParent(arguments);

this.down('#savebtn').on('click', this.saveClient, this);
console.log('ClientSearchPanel::initComponent: done');
},


saveClient: function(button, event, options) {
console.log("ClientAddPanel::saveClient: start");

// some stuff here
console.log("ClientAddPanel::saveClient: form", form);


});


and the code that instantiate the second time my subclass :


var editctab = Ext.create('MyApp.view.ui.ClientAddPanel');

mitchellsimoens
2 Dec 2011, 8:35 AM
Interesting... Ext.create will create a new instance and that will execute initComponent even if the component isn't rendered.

Side note, I see you are adding a listener to the save button in your class... are you using MVC? If so, should that be in the Controller?

pmaisonn
2 Dec 2011, 9:41 AM
Thanks Mitchell for your answer :-| ; I finally found it : Ext Designer generates automatically classes files when exporting the project. I assume there was a conflit between old and new files.

I removed my app/view/ui folder and re-generate the project and it works fine now !