PDA

View Full Version : MVC Special Key Listener



rTankersley
13 Aug 2011, 2:15 PM
How do you listen for a special key using a controller in MVC architecture?

For example, if I have a form, how would I make something like this work:


init: function() {
this.control({
'form': {
specialkey: this.key
}
});
},

key: function() {
console.log('hello');
}


Thanks!

slemmon
13 Aug 2011, 2:57 PM
The form panel itself doesn't have a specialkey event that you can listen to. But, the form fields that you'd put into a form panel often times do. So, you could listen to say all of the textfields or all of the combobox's specialkey events. Or, (untested) you might be able to listen to all of form's child items' specialkey events:


init: function() {
this.control({
'form > textfield': {
specialkey: this.key
}
});
},

key: function() {
console.log('hello');
}


(I think this works, but didn't test it)

init: function() {
this.control({
'form > *': {
specialkey: this.key
}
});
},

key: function() {
console.log('hello');
}

rTankersley
15 Aug 2011, 7:24 AM
They both work. Thank you very much for the help!

grisdip
22 Nov 2011, 10:42 PM
Excusme Im new and, I'm looking for something similar, I tried to get the event and execute a function but I don't undertand who is "this.control" is it my form? or mi field? I tried putting both but getting an error. Thanks for your help