PDA

View Full Version : how to use one button data in another button handler



gokulpotluri
18 Mar 2013, 1:54 AM
Hi

I am having two buttons called button1 and button2 . The event handling for these buttons done in controllers

init:function(){
this.control({
'mypanel button[action=button1]':{
click:this.onButtonClick1
},
'mypanel button[action=button2]':{
click:this.onButtonClick2
}
});

this.application.on({
sendTheClick1:this.caughtTheClick1,
scope:this

});
}

now what i want is, in the function onButtonClick1 which is event handler for button1, i want to change the text of the button2 without using the 'ids'.

please give me some solution.

grgur
18 Mar 2013, 4:18 AM
I always advise not to use action=foo because action is not a predefined configuration option. Use it in Sencha Touch 2, build for production and you're in trouble. Instead, why not using itemId?

You can use refs or query manually, depending on your app's layout.

A simple way to go is to add this bit of code to your btn1 handler:




onButtonClick1: function(button) {
var btn2 = button.up().down('button[action=button2]');
btn.setText('Something else');
}


If the two buttons are siblings, you can also use



var btn2 = button.next('[action=button2]');