-
3 Nov 2011 6:18 PM #1
Unanswered: FormPanel: accessing the data object
Unanswered: FormPanel: accessing the data object
Hi guys,
I'm new to sensha and to some extent js. I've created a test app with list and detail forms, pretty standard stuff I guess. Here's my list definition:
You can see that the selectedJob is passed to the JobEditor.Code:MyApp.views.requestsList = new Ext.List({ id: 'requestsList', store: 'RequestJobStore', onItemDisclosure: function (record) { var selectedJob = record; MyApp.views.JobEditor.load(selectedJob); MyApp.views.viewport.setActiveItem('JobEditor', { type: 'slide', direction: 'left' }); }, itemTpl: '<div class="list-item-title">{Name}</div><div class="list-item-jobfield">{Company}</div>', listeners: { 'render': function (thisComponent) { thisComponent.getStore().load(); } } });
Now the JobEditor displays some of the fields in the Job data object. In the JobEditor's code I know I can get the value of these by
What I want to know is, how can I get the value of the other fields? The fields in the JSON object passed to the FormPanel, that do not have textfields?Code:MyApp.views.JobEditor.getValues().FieldName
I'm hoping I don't have to resort to dodgy invisible textfields or something. Not that I know how to do that either. Can anyone advise me please?
-
4 Nov 2011 6:33 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3105
I would use setRecord on the form and pass the record that was tapped on. You can then use updateRecord when you save the form and getRecord to get the record.
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.
-
4 Nov 2011 6:36 AM #3
Hi kalor.
As you said, getValues() returns an object containing the value of each field in the form, so if you don't have a field associated to the field values that you want to retrieve, you are not able to do that in that way.
However, I suggest you to use "hiddenfield" to contains the values of those fields that you don't want to show on your form, but that you still want to be able to get their values using the "getValues" function.
Hope this helpsSencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
4 Nov 2011 7:13 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3105
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.
-
4 Nov 2011 7:25 AM #5
I agree, but we don't know his application architecture, so he probably need to save the record inside the controller, and when he need to get all the complete record data (the one edited by the form and the one not visible inside the form), should merge the one retrieved by calling the "form.getValues() function" with the one stored inside the saved record.
However I agree on the fact that keeping the DOM clear on mobile apps has to be a priority.Sencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
4 Nov 2011 8:02 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,624
- Vote Rating
- 434
- Answers
- 3105
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.
-
6 Nov 2011 9:23 PM #7
OK I think I have the record, but I don't know the syntax to use it. I thought I'd be able to use record.fields[0] or record.CompanyName or something. How do I get the value of a specific field?
-
7 Nov 2011 12:09 AM #8
If your record has a CompanyName field, that you just need to call
http://docs.sencha.com/touch/2-0/#!/...del-method-getCode:record.get('CompanyName');
In the same way, if you have to set a field value, just call
http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Model-method-setCode:record.set('CompanyName', 'My Company Name');
Hope this helps.Sencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata


Reply With Quote