Threaded View

  1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    27
    Answers
    1
    Vote Rating
    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
                }
            }
        ]
    });

Thread Participants: 1

Tags for this Thread