-
3 Jun 2012 11:21 PM #1
Unanswered: Problems with forms, records and sliders
Unanswered: Problems with forms, records and sliders
In my app I use a local store for personal patient data and a form where the user can edit their data.
The problem is that the data in the store are not loaded into the form. The text and slider fields remain at null value when the form is displayed.
The data are stored in the local store, though, as the Chrome debugger shows. The workaround below for loading the data works, but this is not the way to do it.
Where am I going wrong?
Code:Ext.define( 'BT.model.Patient', { extend: 'Ext.data.Model' , config: { fields: [ {name: "id", type: "number" /* , default: "1" does not work with samsung} */ } , {name: "name", type: "string"} , {name: 'jahre', type: 'number' } , {name: 'gewicht', type: 'number' } ] , proxy: { type: 'localstorage' , id: 'Patient' } } }); Ext.define( 'BT.store.Patient', { extend: 'Ext.data.Store' , requires: ['Ext.data.Store','BT.model.Patient'] , config: { id: 'storePatient' , storeId: 'storePatient' , model: 'BT.model.Patient' , autoLoad: true , autoSync: true } }); Ext.create('BT.store.Patient'); Ext.define('BT.view.Patient', { extend: 'Ext.form.Panel' , requires: ['Ext.field.Slider', 'BT.store.Patient'] , config: { id: 'formPatient' , title: 'Patient' , fields: ['name','jahre','gewicht'] , iconCls: 'user' , iconMask: true , listeners: { initialize: function(obj, options) { log( 'initialize...'); obj.storePatient = Ext.getStore( 'storePatient' ); if (obj.storePatient.data.length == 0) { log('adding...'); obj.storePatient.add({id:1,name:'(Name des Kindes)',jahre:'0',gewicht:'0'}); obj.storePatient.sync(); } var theRecord = obj.storePatient.getAt(0); log(theRecord); obj.setRecord(theRecord); console.log(obj.getRecord()); // obj.getRecord().save(); // workaround for loading data into theh form obj.getComponent('jahre').setValue(theRecord.get('jahre')); obj.getComponent('name').setValue(theRecord.get('name')); obj.getComponent('gewicht').setValue(theRecord.get('gewicht')); } } , items: [ { xtype: 'toolbar' , docked: 'top' , items: [ { xtype: 'button' , text: 'Weiter' , ui: 'forward' , docked: 'right' , handler: function() {this.getParent().getParent().getParent().setActiveItem(2);} } ] } , { xtype: 'textfield' , name: 'name' , id: 'name' , label: '$Name' , cls: 'w100' , listeners : { change: function (obj, newValue, oldValue, options) { this.getParent().getRecord().set(this.getName(),this.getValue()); } } } , { xtype: 'sliderfield' , name: 'jahre' , id: 'jahre' , label: '<div style="float:left">' + '$Alter' + '</div><div class="label_einheit_rechts"><span id="label_alter"></span></div>' , allowThumbsOverlapping: true , minValue: 5 , maxValue: 15 , listeners: { change: function (obj, newValue, oldValue, options) { this.getParent().getRecord().set(this.getName(),this.getValue()); } , drag: function(obj, slider, thumb, newValue, oldValue) { document.getElementById('label_alter').innerHTML = (newValue > 0 ? newValue + ' ' + '$Jahre' : ''); } } } , { xtype: 'sliderfield' , name: 'gewicht' , id: 'gewicht' , label: '<div style="float:left">' + '$Gewicht' + '</div><div class="label_einheit_rechts"><span id="label_gewicht"></span></div>' , minValue: 5 , maxValue: 70 , listeners: { change: function (obj, newValue, oldValue, options) { this.getParent().getRecord().set(this.getName(),this.getValue()); } , drag: function(obj, slider, thumb, newValue, oldValue) { document.getElementById('label_gewicht').innerHTML = (newValue > 0 ? newValue + ' ' + '$kg': ''); } } } ] // items } });
-
5 Jun 2012 11:18 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 436
- Answers
- 3113
So is the issue getting the record? Or apply the values from the record to the form?
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.
-
7 Jun 2012 1:55 AM #3
Applying the values from the record to the form?
Applying the values from the record to the form?
Hi, this is interesting and more or less what I'm looking for. Im my case, the question is more how does one
apply the values from the record to the form?
-
7 Jun 2012 4:22 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 436
- Answers
- 3113
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.
-
7 Jun 2012 4:33 AM #5
I've done
I've done
...not working =(
NB: my form contains radio & select fields (shouldn't make a difference though)
field names in form matches of my modelCode:var myForm = Ext.getCmp('form'); var store = Ext.getStore('User'); myForm.setRecord(store);
model
No errors occur.. Any ideas? I'm know I'm missing something here!Code:Ext.define('MyApp.model.User',{ extend: 'Ext.data.Model', config: { fields:[ 'bouquet', 'rated', 'since', 'age', 'gender' ] } });
-
7 Jun 2012 4:34 AM #6Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 436
- Answers
- 3113
The names of the modal and fields match?
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.
-
7 Jun 2012 4:38 AM #7
In deed
In deed
They match ... (in bold)
Code:config: { items: [ { xtype: 'fieldset', title: 'I am a ...', instructions: 'Change your personal settings as desired.', defaults: { labelAlign: 'left', labelWidth: labelwidth, userClearIcon: true }, items: [ { xtype: 'radiofield', name: 'gender', label: 'Male:', value: 'male', //checked: true }, { xtype: 'radiofield', name: 'gender', label: 'Female:', value: 'female' } ] }, { xtype: 'fieldset', title: 'who was born in...', items: [ { xtype: 'spinnerfield', id: 'age', name: 'age', minValue: minYear, maxValue: maxYear, increment: 1, cycle: false //value: '1975' } ] }, { xtype: 'fieldset', title: 'and like...', defaults: { xtype: 'selectfield', labelAlign: 'left', labelWidth: labelwidth, userClearIcon: true }, items: [ { label: 'Bouquet:', name: 'bouquet', valueField: 'bouquet_value', displayField: 'bouquet_name', store: 'Bouquet', value: '7' }, { label: 'Movies made since:', name: 'since', valueField: 'since_value', displayField: 'since_name', store: 'Since' }, { label: 'Movies rated at least:', name: 'rated', valueField: 'rated_value', displayField: 'rated_name', store: 'Rated' } ] }, { xtype: 'button', text: 'Save', id: 'btnsave', ui: 'confirm', // Displays a 'Saving...' message handler: function () { Ext.Viewport.getActiveItem().setMasked({ xtype: 'loadmask', message: 'Saving...' }); setTimeout(function() { Ext.Viewport.getActiveItem().setMasked(false); }, 500); } } ],
-
7 Jun 2012 5:04 AM #8Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 436
- Answers
- 3113
For radio there is a bug/behavior that the getValue method of the radio/checkbox returns true/null not the actual value. If you override getValue method on the checkbox to return the _value then it should work then.
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.
-
7 Jun 2012 5:09 AM #9
My apologies Mitchell, but could you provide a sample of this "If you override getValue method on the checkbox to return the _value then it should work then." Thank you (really appreciated)
-
7 Jun 2012 5:19 AM #10Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,710
- Vote Rating
- 436
- Answers
- 3113
Here is a quick test case I created
Code:Ext.define('Override.field.Radio', { override : 'Ext.field.Radio', getValue : function() { return this._value; } }); Ext.define('MyModel', { extend : 'Ext.data.Model', config : { fields : [ 'gender' ] } }); Ext.application({ name : 'Test', launch : function() { new Ext.form.Panel({ fullscreen : true, items : [ { xtype : 'radiofield', label : 'Male', name : 'gender', value : 'male' }, { xtype : 'radiofield', label : 'Female', name : 'gender', value : 'female' }, { xtype : 'button', text : 'Set Record', handler : function(button) { var form = button.up('formpanel'), record = new MyModel({ gender : 'female' }); form.setRecord(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.


Reply With Quote