1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    51
    Answers
    7
    Vote Rating
    0
    noromamai is on a distinguished road

      0  

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

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,073
    Answers
    3500
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Why not use Ext.Msg.confirm instead of a regular javascript confirm popup?
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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
    Nov 2011
    Posts
    51
    Answers
    7
    Vote Rating
    0
    noromamai is on a distinguished road

      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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,073
    Answers
    3500
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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.

  6. #5
    Sencha User
    Join Date
    Nov 2011
    Posts
    51
    Answers
    7
    Vote Rating
    0
    noromamai is on a distinguished road

      0  

    Default


    thanks!

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

Thread Participants: 1