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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,317
    Answers
    3883
    Vote Rating
    1291
      1  

    Default

    You have a scoping issue. The onSuccess scope will not automatically be of the controller
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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 in print!

    When posting code, please use BBCode's CODE tags.

  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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,317
    Answers
    3883
    Vote Rating
    1291
      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
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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 in print!

    When posting code, please use BBCode's CODE tags.

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
  •