1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    27
    Vote Rating
    1
    Answers
    1
    new boy is on a distinguished road

      0  

    Default 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:
    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'
                        },
    ...
    Controller:

    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
        },
    Thanks.

  2. 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
                }
            }
        ]
    });

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,641
    Vote Rating
    434
    Answers
    3107
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    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.

  4. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    27
    Vote Rating
    1
    Answers
    1
    new boy is on a distinguished road

      0  

    Default


    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 tried
    myHidden.setValue(1);
    and
    myHidden.setValue('1');


    Do you have another suggestion?

    Thanks



  5. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,641
    Vote Rating
    434
    Answers
    3107
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    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.

  6. #5
    Sencha User
    Join Date
    Mar 2012
    Posts
    27
    Vote Rating
    1
    Answers
    1
    new boy is on a distinguished road

      0  

    Default


    Thanks very much.

    It appears that my 'values' in
    var values = form.getValues()
    does not change when the form is changed, your
    field.getValue()
    reads in the current value. Which all makes sense.

    Thanks again.

Tags for this Thread