PDA

View Full Version : FieldSet - loadRecord?!



Jakob
25 Jan 2013, 1:43 PM
Hey there,

i have a problem to reference my fieldset/form in my controller and load the record in it.

View:

Ext.define('RAR.view.order.OrderForm' ,{
extend: 'Ext.form.FieldSet',
alias : 'widget.orderform',


margin: '0 0 0 10',


title:'Order details',


defaults: {
width: 240,
labelWidth: 90
},


defaultType: 'textfield',


items: [{
fieldLabel: 'Id',
name: 'IDrec'
},{
fieldLabel: 'Firma',
name: 'Firma'
},{
fieldLabel: 'Nettosumme',
name: 'NSumme'
},{
xtype: 'datefield',
fieldLabel: 'Datum',
name: 'RecDatum'
}]
});


Controller:


Ext.define('RAR.controller.OrderController', {
extend: 'Ext.app.Controller',


stores: ['Orders'],


models: ['Order'],


views: [
'order.OrderGrid',
'order.OrderForm',
'order.OrderPanel'
],


refs: [{
ref: 'orderForm',
selector: 'orderform'
}],

init: function() {


this.control({
'ordergrid': {
selectionchange: this.gridSelectionChange
}
});
},


gridSelectionChange: function(model, records) {


if (records[0]) {
this.getOrderForm().getForm().loadRecord(records[0]);
}
}

});


When I excecute this i get the error: "TypeError: this.getOrderForm(...).getForm is not a function"

Before this, I tried it with another reference into the OrderController:



refs: [{
ref: 'orderForm',
selector: 'form'
}],


This works, but now I must specify the form I would fill.

I think my question is now: Which function or reference I can use to load the record in my FieldSet.

Thanks for your time.
Jakob

skirtle
25 Jan 2013, 4:18 PM
A fieldset is not a form. The method's getForm and loadRecord are method's of Ext.form.Panel:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.Panel

Whereas what you have is a Ext.form.FieldSet:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.FieldSet

If you only have a small number of fields then you could just copy the values from the record manually. If you really want to use loadRecord then just add in a form. i.e. Make the first child of the fieldset a form and move the fields inside it.

Jakob
26 Jan 2013, 10:37 AM
Thanks for reply!

I get the point, but why can i reference the same fieldset with



refs: [{
ref: 'orderForm',
selector: 'form'
}],


and then I can use the loadRecord method. Is there a possibility to specify this reference to get alwas the right form? Do u know what I mean?

Greets, Jakob

skirtle
26 Jan 2013, 4:00 PM
but why can i reference the same fieldset with...

You can't. The selector is 'form', which will match an Ext.form.Panel, not the fieldset.

To target more specific components you can use a custom xtype (via subclassing) or an itemId. Personally I wouldn't use an itemId unless I also have a custom xtype earlier in the selector.

If you haven't already, make sure you've read this explanation of component queries:

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.ComponentQuery

Perhaps I still haven't understood your question?

Jakob
26 Jan 2013, 4:48 PM
Thanks!