Results 1 to 5 of 5

Thread: confirm() callback function not passing button variable

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    51
    Answers
    7
    Vote Rating
    0
      0  

    Default Answered: confirm() callback function not passing button variable

    I have a list with items and want to delete on swipe. The way i have it now is that when you swipe, it will prompt you whether you want to delete or not. after clicking yes or no the callback function is called. But i can't find out which button is clicked. i pass the index and the button clicked to a new function, but the value of button is always undefined, i do get the index right.

    this is in app.views.CustomerList.js:

    Code:
    itemswipe: function(list, index) {
                    Ext.dispatch({
                       controller: app.controllers.customer,
                       action: 'confirmremove',
                       index: index,
                       scope: this
                    });
            }
    this is in customer.js:

    Code:
    confirmremove: function(params) {
            var customer = app.stores.customer.getAt(params.index);
            // android quirk? doesn't display "message", only title
            confirm('Delete?\n' + 
                    customer.data.first + ' ' + customer.data.last + '\n' +
                    customer.data.address + '\n' +
                    customer.data.zipcode + ' ' + customer.data.city, this.remove(this.button, params.index));
        },
        remove: function(btn, index) {
            if (btn == 'yes') {
                Ext.Msg.alert('yes was clicked on ' + index);
            }
        }

  2. Why not use Ext.Msg.confirm instead of a regular javascript confirm popup?

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      0  

    Default

    Why not use Ext.Msg.confirm instead of a regular javascript confirm popup?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    51
    Answers
    7
    Vote Rating
    0
      0  

    Default

    I found that problem. It was a typo. It works "more" now using Ext.Msg.confirm(), but now banging my head against another problem. I keep getting "TypeError: Result of expression 'b' [undefined] is not an object. at file:///android_asset/www/sencha/sencha-touch.js:6" as soon as i click YES or NO. I've changed everything to it's simplest form and still get that error. Can't use js console to debug because it's running on android emulator (or can i?).

    Code:
    confirmremove: function(params) {
            var customer = app.stores.customer.getAt(params.index);
            Ext.Msg.confirm('Delete', 
                    customer.data.first + ' ' + customer.data.last + '\n' +
                    customer.data.address + '\n' +
                    customer.data.zipcode + ' ' +
                    customer.data.city, this.remove(this.button, params.index));
        },
        remove: function(button, index) {
            if (button == 'yes') {
                Ext.Msg.alert('yes was clicked on ' + index);
            }
        }

  5. #4
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3932
    Vote Rating
    1272
      0  

    Default

    You need to put the function, you are executing it right away...

    Code:
    Ext.Msg.confirm('Title', 'Message', this.remove);
    If you want to pass an extra parameter (as the button is the only one) then you can:

    Code:
    Ext.Msg.confirm('Title', 'Message', Ext.util.Functions.createDelegate(this.remove, this, [params.index], true));
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  6. #5
    Sencha User
    Join Date
    Nov 2011
    Posts
    51
    Answers
    7
    Vote Rating
    0
      0  

    Default

    thanks!

    that solved the problem. just copy pasted it, but will read up on createDelegate() now.

Posting Permissions

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