Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sencha Touch Toggle Button

How could you run some action when pushing a toggle button like this:

{
    xtype: 'togglefield',
    name: 'enableSnd',
    label: 'Sound',
    value : 1    
}

?

like image 818
headkit Avatar asked Apr 26 '11 21:04

headkit


2 Answers

Here's an example I'm currently using in an app of mine. I use the "beforechange" function to check and validate some data before I perform the real action in "change".

{
    xtype: 'togglefield',
    name: 'toggleName',
    label: 'My Toggle Field',
    listeners: {
        beforechange: function (slider, thumb, newValue, oldValue) {
            if (oldValue == 0 && newValue == 1) {
                // Changing from off to on...validate something?
            }
        },
        change: function (slider, thumb, newValue, oldValue) {
            if (oldValue == 0 && newValue == 1) {
                // Changing from off to on...do something?
            }
            else if (oldValue == 1 && newValue == 0)
                // Changing from on to off...do something?
        }
    }
}
like image 88
robertmiles3 Avatar answered Oct 14 '22 03:10

robertmiles3


Have a look at the official documentation in sencha:

  • http://dev.sencha.com/deploy/touch/docs/

For a simple button:

    var playPauseButton = new Ext.Button({
    ui: 'small',
    text: 'Play',
    listeners: {
      tap: function() {
      Ext.Ajax.request({
        url: '/api/pause',
        success: updateStatus,
        failure: updateStatus });
      }
    }
    });

For a toggle, event seems to be dragend...

like image 24
Oct Avatar answered Oct 14 '22 04:10

Oct