-
18 Apr 2012 1:51 AM #1
Answered: numberfield value reading old value, not updated value
Answered: numberfield value reading old value, not updated value
When I set the value of a numberfield and then read it back, I get the old value not the new one.
However the UI shows the new value. I'm assuming its either my code is reading back a cached value, or a timing issue.
Can anyone tell me what is going on and help me fix this?
Here are the snippets of my code
View:
Controller:Code:Ext.define('MyApp.view.view1', { extend : 'Ext.form.FormPanel', xtype : 'screen', config : { name : 'xyx', scrollable : { direction : 'vertical', directionLock : true }, items : [ { xtype : 'numberfield', name : 'hiddenName', label : 'will be hidden' }, ...
Thanks.Code:... control : { 'screen component[name="anyOtherField"]' : { change : "onChange" }, ... onChange : function(field) { var form = field.up('screen'); var values = form.getValues(); var myHidden = form.query('[name="hiddenName"]')[0]; console.log (" value of myHidden is ", values.myHidden); // displays value correctly myHidden.setValue("1") ; // set the value to "1" which is displayed correctly on the user interface console.log (" value of myHidden is ", values.myHidden); // displays old value not the new value },
-
Best Answer Posted by mitchellsimoens
String or number working for me:
Code:new Ext.form.Panel({ fullscreen : true, items : [ { xtype : 'numberfield', label : 'Test' }, { xtype : 'button', text : 'Set Value', handler : function (button) { var form = button.up('formpanel'), field = form.down('numberfield'); console.log(field.getValue()); //null field.setValue(2); console.log(field.getValue()); //2 field.setValue('2'); console.log(field.getValue()); //2 } } ] });
-
18 Apr 2012 4:46 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
Try setting the value of an actual number not a string.
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.
-
18 Apr 2012 5:15 AM #3
Mitchell, thanks for the suggestion.
Unfortunately it makes no difference.
I originally had it as a number which was the obvious choice, and changed to text when that didn't work.
I have triedmyHidden.setValue(1);andmyHidden.setValue('1');
Do you have another suggestion?
Thanks
-
18 Apr 2012 5:21 AM #4Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
String or number working for me:
Code:new Ext.form.Panel({ fullscreen : true, items : [ { xtype : 'numberfield', label : 'Test' }, { xtype : 'button', text : 'Set Value', handler : function (button) { var form = button.up('formpanel'), field = form.down('numberfield'); console.log(field.getValue()); //null field.setValue(2); console.log(field.getValue()); //2 field.setValue('2'); console.log(field.getValue()); //2 } } ] });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.
-
18 Apr 2012 6:17 AM #5
Thanks very much.
It appears that my 'values' invar values = form.getValues()does not change when the form is changed, yourfield.getValue()reads in the current value. Which all makes sense.
Thanks again.


Reply With Quote