PDA

View Full Version : Can't retrieve child item in Window



Ooypunk
16 Feb 2011, 2:21 PM
Probably similar to the thread I started earlier (http://www.sencha.com/forum/showthread.php?124093-Combobox-How-to-get-the-form), now I can't retrieve a child item in a Window.
This is the code:
Win_Order_Toevoegen = Ext.extend(FormWindow, {
constructor: function(config) {
config = Ext.apply({
title: 'Order toevoegen',
items: new Form_Order_Toevoegen()
}, config);

Win_Order_Toevoegen.superclass.constructor.call(this, config);

this.on('hide', function(){
var form = this.findByType('form');
form.reset();
orderdetailStore.loadData({});
orderDataStore.reload();
var bla;
});
} // end of class constructor
}); // eo Win_Order_Toevoegen (FormWindow extend)
For some reason findByType returns an empty array. I don't understand that, because I clearly state "items: new Form_Order_Toevoegen()" in the config of the constructor.

Ooypunk
19 Feb 2011, 5:50 AM
Anyone?

Condor
22 Feb 2011, 1:53 PM
this.findByType('form') will return your FormPanel, but you need the inner BasicForm (using getForm()) to call reset().

Also, 'this' will probably be the window in a 'hide' event, but in most cases you should specify the scope when registering an event handler.

Ooypunk
22 Feb 2011, 2:05 PM
this.findByType('form') will return your FormPanel, but you need the inner BasicForm (using getForm()) to call reset().Yes, well, I need to get that FormPanel first, but findByType returns an empty array (according to FireBug that is). That empty array has no method called getForm().



Also, 'this' will probably be the window in a 'hide' event, but in most cases you should specify the scope when registering an event handler.'this' seems to be the Window indeed; in Firebug I can see 'this' has (for example) a 'closeAction' defined.

Condor
22 Feb 2011, 11:28 PM
Strange, this should work:

var form = this.findByType('form')[0].getForm();

But you already know the items structure, so using 'ref' or 'itemId' would be better, e.g.

Win_Order_Toevoegen = Ext.extend(FormWindow, {
constructor: function(config) {
config = Ext.apply({
title: 'Order toevoegen',
items: new Form_Order_Toevoegen(),
ref: 'form', // example 1
itemId: 'form' // example 2
}, config);
Win_Order_Toevoegen.superclass.constructor.call(this, config);
this.on('hide', function(){
var form = this.form; // uses 'ref'
var form = this.getComponent('form'); // uses 'itemId'
form.getForm().reset();
orderdetailStore.loadData({});
orderDataStore.reload();
var bla;
});
}
});

Ooypunk
23 Feb 2011, 11:53 AM
Strange, this should work:

var form = this.findByType('form')[0].getForm();Yes, I thought so too, but it returns an empty array, so form[0].getForm() won't work (I tried even: didn't work). A bug?


But you already know the items structure, so using 'ref' or 'itemId' would be better, e.g.[...]
I fiddled a bit with what you suggested in your example code, and this is what works now:

Win_Order_Toevoegen = Ext.extend(FormWindow, {
constructor: function(config) {
config = Ext.apply({
title: 'Order toevoegen',
items: [
new Form_Order_Toevoegen({ref: 'form_order_toevoegen'})
]
}, config);

Win_Order_Toevoegen.superclass.constructor.call(this, config);

this.on('hide', function(){
var form = this.form_order_toevoegen.getForm();
form.reset();
orderdetailStore.loadData({});
orderDataStore.reload();
});
} // end of class constructor
}); // eo Win_Order_Toevoegen (FormWindow extend)I set the 'ref' for the form in the Form instance itself; that way it will appear in its ownerCt (being the window), so I can get at it with 'this.refName'.

Thanks for the pointer! :)