Results 1 to 4 of 4

Thread: Set textfield value outside of the config area in a callback function ?

  1. #1
    Sencha User
    Join Date
    Jul 2011
    Posts
    18
    Vote Rating
    0
      0  

    Default Answered: Set textfield value outside of the config area in a callback function ?

    I'm trying to learn how to make PhoneGap and Sencha work together. (I'm a little new to both however).

    So in a controller on a button click I fire off a phonegap function that calls for a callback function on success (which delivers the compass direction).

    This works fine. (at least when I alert the compass reading).

    However, I was hoping to set a textfield with the heading. But I cannot figure out how to get to work outside of the config area ... can someone clue me in?

    ** NOTICE THE setValue that sets to NOPE! This works if I uncomment it... I assume because it is inside the config area...but the onSuccess will not set this textfield.

    Code:
    config: {
            refs: {
                homePanel: 'homePanel',
                testText: '#testTextField'
            },
            control: {
                homepanel: {
                    activate: function () {
                        //alert('activate');
                    }
                },
                'button[action=homeExample]': {
                    tap: function () {
                        navigator.compass.getCurrentHeading(this.onSuccess,this.onError);
                        //this.getTestText().setValue('NOPE!');
                    }
                },
                testText: {
                    change: function (field, newValue, oldValue) {
                        //alert(this.getTestText().getValue());
                      
                    }
                }
            }
        },
        
         onSuccess: function (heading) {
            this.getTestText().setValue('Heading: ' + heading.magneticHeading);
        }

  2. Or you can change the scope:

    Code:
    var bind = Ext.bind;
    
    navigator.compass.getCurrentHeading(
        bind(this.onSuccess, this),
        bind(this.onError, this)
    );
    Now in your onSuccess/onError, the scope (this) is that of the controller.

  3. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,062
    Answers
    3976
    Vote Rating
    1391
      1  

    Default

    You have a scoping issue. The onSuccess scope will not automatically be of the controller
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Jul 2011
    Posts
    18
    Vote Rating
    0
      0  

    Default

    I was able to change the textbox by using

    Code:
     onSuccess: function (heading) {
         	Ext.getCmp('testTextField').setValue('Heading: ' + heading.magneticHeading);
        }
    Although that works, I'm sure its not the planned pattern.

  5. #4
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,062
    Answers
    3976
    Vote Rating
    1391
      1  

    Default

    Or you can change the scope:

    Code:
    var bind = Ext.bind;
    
    navigator.compass.getCurrentHeading(
        bind(this.onSuccess, this),
        bind(this.onError, this)
    );
    Now in your onSuccess/onError, the scope (this) is that of the controller.
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •