Nilanchala
Nilanchala

Reputation: 5941

how to handle listener for option control in sencha touch

I have an app where i am using the options control. Now i don't know how can i handle the event when the option changes in option control using sencha touch. Here is the code below which has options. Any help is highly appreciated.

Ext.regModel('Contact', {
    fields: ['firstName', 'lastName']
});

var store1 = new Ext.data.JsonStore({
    model  : 'Contact',
    autoLoad : true,
           autoDestroy : true, 
    data: [
        {firstName: 'Tommy',   lastName: 'Maintz'},
        {firstName: 'Rob',     lastName: 'Dougan'},
        {firstName: 'Ed',      lastName: 'Spencer'},        
        {firstName: 'Abraham', lastName: 'Elias'},
        {firstName: 'Jay',     lastName: 'Robinson'}
    ]
});

new Ext.Application({
    launch: function() {
       var panel =  new Ext.Panel({
            fullscreen: true,
            id:'thePanel',
            layout: 'auto',
            style: 'background-color:darkblue',
            scroll:'vertical'
        });
//do this in your dynamically called function
    var list = new Ext.List({
        id :'theList',
        itemTpl : '{firstName} {lastName}',
        store: store1,
        width: '100%',
        scroll:false
    });

var stateList = new Ext.form.Select({
    label : 'State',
    name: 'state',
    widht: '100%',
    options: [
        {text: 'First Option',  value: 'first'},
        {text: 'Second Option', value: 'second'},
        {text: 'Third Option',  value: 'third'}
    ],
    autoLoad : true,
    autoDestroy : true
});

    panel.items.add(list);
    panel.items.add(stateList);
    panel.doLayout();               
    }
});

Upvotes: 1

Views: 1265

Answers (2)

ilija139
ilija139

Reputation: 2974

var stateList = new Ext.form.Select({
 label : 'State',
 name: 'state',
 widht: '100%',
 options: [
    {text: 'First Option',  value: 'first'},
    {text: 'Second Option', value: 'second'},
    {text: 'Third Option',  value: 'third'}
 ],
 autoLoad : true,
 listeners: {
     change:function(field,value){
       console.log(field+' '+value);
     }
 },

});

You need to change it like this

Upvotes: 1

Alex
Alex

Reputation: 5724

var stateList = new Ext.form.Select({
 label : 'State',
 name: 'state',
 widht: '100%',
 options: [
    {text: 'First Option',  value: 'first'},
    {text: 'Second Option', value: 'second'},
    {text: 'Third Option',  value: 'third'}
 ],
 autoLoad : true,
 autoDestroy : true,
 listeners= {
    blur: function(selectField, e) {
            console.log(selectField.getValue());
    }
 }

});

Upvotes: 0

Related Questions