PDA

View Full Version : Controllers - event listening



Zavel
21 Feb 2012, 5:27 PM
Hi, i've been attempting to use a controller and connect it to a button (using Sencha designer 2).

I added a controller, and then a controller action. In the action i've specified that the target type is "button", which then gives me a dropdown of choices for the EventBinding name - from which i selected "tap". My ControlQuery is set to "button" which maps the listener to listen for tap events coming from all buttons (i'm assuming).

While this listens to all tap events from all buttons, how is it possible to listen for a tap event coming from one specific button? is that the way to do it?

Please let me know.
Thanks,
Shane.

Zavel
21 Feb 2012, 5:29 PM
Or does the "tap" method, which occurs when any button is pressed - need to contain a large if-else statement to actually check the instance of button passed into the handler method, to determine which button has fired the event and therefore which action to take ?

- Shane

bhaidaya
21 Feb 2012, 5:35 PM
In the selector field you can specify a great level of detail.

The code below would look for an element with the id 'app-controls' and within that element a button with a custom attribute named action set to 'logout' and fire if it was clicked.


this.control({
//When you press the logout button...
'#app-controls button[action=logout]': {
// 'controls button[action=logout]': {
click: {
fn: this.logout
}
}

aconran
21 Feb 2012, 5:42 PM
To add the custom attribute of action 'logout'. You do the following. Select the button in the top right of the inspector.

In the Search/QuickSet field above the property grid you can put in:


action: 'logout'


Then click add. You can also type action, then click add, and then configure it to logout (and/or correct any mistakes you may have made)

Zavel
21 Feb 2012, 5:58 PM
Just a side note would i be right if i assumed that the syntax:

#elementID button[action=logout]

could also be used to check against any attribute of the button in question, and that action=logout could be "anycustomattribute=logout" ?

aconran
21 Feb 2012, 6:22 PM
#elementId would be the id or itemId of a parent container of that button, not an actual element.

And yes you can check any attribute, just like a css selector.