-
18 Oct 2012 5:03 AM #1
Answered: Problem setting record to panel from controller
Answered: Problem setting record to panel from controller
Hi,
I work with MVC.
I have a navigationview with a list. when you press the disclose button, an event is fired. the chosen record is passed with the event.
within the controller, I create a detailsview (this is a Panel), I add the record and then I push this detailsview onto the navigationview. the detailsview has fields which names correspond with the names from the model.
the problem is that I see the detailsview but the fields are empty.
The record isn't empty within the controller.
controller:
Detailsview:Code:onMyRequestsDetails : function(record) { //this is the navigationview which is defined within REFS var view = this.getMyRequests(); //this is the detailsview var request = Ext.create('LeaveRequest.view.Request' , {scrollable:true}) ; //the record I want to add request.setRecord(record) ; //push details on navigationview view.push(request); }
Can somebody help?Code:... initialize : function() { this.callParent(arguments); var leaveType = { xtype : 'selectfield', name : 'AbsenceTypeName', id : 'AbsenceTypeName', label : 'Leave type', store : storeAT, valueField : 'AbsenceTypeCode', displayField : 'AbsenceTypeName', cls : 'requestLeaveType' }; ... this.add([leaveType]); ...
-
Best Answer Posted by mitchellsimoens
Is LeaveRequest.view.Request a form panel?
-
20 Oct 2012 7:48 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3155
Is LeaveRequest.view.Request a form panel?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
20 Oct 2012 8:16 AM #3
I just tested it and it works!
I had Ext.Panel, not Ext.form.Panel
Thank you so much, I've been searching for days
-
22 Oct 2012 12:54 AM #4
Unfortunatelly, this doesn't work for selectfield =(
textfields, no problem. so the code below will work, but I need a selectfield.
Do I need to do something special for this?Code:... initialize : function() { this.callParent(arguments); var leaveType = { xtype : 'textfield', name : 'AbsenceTypeName', id : 'AbsenceTypeName', label : 'Leave type', //store : storeAT, //valueField : 'AbsenceTypeCode', //displayField : 'AbsenceTypeName', cls : 'requestLeaveType' }; ... this.add([leaveType]); ...
-
22 Oct 2012 4:21 AM #5Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3155
The value you pass must be a value in the store based on the valueField. It will work just like any other field.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
22 Oct 2012 4:41 AM #6
It still doesn't work

Even when I pass an hardcoded value from the controller to the panel
(AbsenceTypeCode : '0101')
it will always display the first value from the store.
Code:leaveType = { xtype : 'selectfield', name : 'AbsenceTypeCode', id : 'AbsenceTypeCode', label : 'Leave type', store : storeAT, valueField : 'AbsenceTypeCode', displayField : 'AbsenceTypeName', cls : 'requestLeaveType' };
-
22 Oct 2012 5:12 AM #7Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3155
If the select field does not have a record by default the first option is picked. Here is an example of setRecord:
Code:Ext.define('MyModel', { extend : 'Ext.data.Model', config : { fields : [ 'text', 'select' ] } }); Ext.Viewport.add({ xtype : 'formpanel', items : [ { xtype : 'textfield', label : 'Text', name : 'text' }, { xtype : 'selectfield', label : 'Select', name : 'select', store : { fields : [ 'text', 'value' ], data : [ { text : 'First Option', value : 'first' }, { text : 'Second Option', value : 'second' }, { text : 'Third Option', value : 'third' } ] } }, { xtype : 'button', text : 'Set Value', handler : function(btn) { var form = btn.up('formpanel'), rec = new MyModel({ text : 'Foo', select : 'second' }); form.setRecord(rec); } } ] });Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
22 Oct 2012 6:49 AM #8
Thank you!
I finally found the problem.
I fill the selectfield with data from a store.
The problem is that the fields of the selectfield have a different name than 'value' and 'text'.Code:storeAT = Ext.create('LeaveRequest.store.AbsenceTypeStore'); ... var leaveType = { xtype : 'selectfield', name : 'AbsenceTypeCode', id : 'AbsenceTypeCode', label : 'AbsenceTypeCode', store : storeAT, valueField : 'AbsenceTypeCode', displayField : 'AbsenceTypeName' }
So when I tried to set a different value, it couldn't match with anything from the options in selectfield,
so it just showed the first one.
So, when i replace the bold code above into this:
then it works.Code:store : { fields : ['text', 'value'], data : [{ value : '0200', text : 'Vacation' }, { value : '0100', text : 'Sickness' }] }
so i can't use a store in a selectfield.


Reply With Quote