1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    39
    Vote Rating
    0
    rTankersley is on a distinguished road

      0  

    Default Answered: MVC Special Key Listener

    Answered: MVC Special Key Listener


    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:

    Code:
    init: function() {
            	this.control({         
    			'form': {
    				specialkey: this.key
    			}
    		});
    	},
      
    	key: function() {
    		console.log('hello');
    	}
    Thanks!

  2. 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:

    Code:
    init: function() {
            this.control({         
    		'form > textfield': {
    			specialkey: this.key
    		}
    	});
    },
      
    key: function() {
    	console.log('hello');
    }
    (I think this works, but didn't test it)
    Code:
    init: function() {
            this.control({         
    		'form > *': {
    			specialkey: this.key
    		}
    	});
    },
      
    key: function() {
    	console.log('hello');
    }

  3. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    5,120
    Answers
    405
    Vote Rating
    188
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    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:

    Code:
    init: function() {
            this.control({         
    		'form > textfield': {
    			specialkey: this.key
    		}
    	});
    },
      
    key: function() {
    	console.log('hello');
    }
    (I think this works, but didn't test it)
    Code:
    init: function() {
            this.control({         
    		'form > *': {
    			specialkey: this.key
    		}
    	});
    },
      
    key: function() {
    	console.log('hello');
    }

  4. #3
    Sencha User
    Join Date
    May 2011
    Posts
    39
    Vote Rating
    0
    rTankersley is on a distinguished road

      0  

    Default


    They both work. Thank you very much for the help!

  5. #4
    Sencha User
    Join Date
    Apr 2010
    Posts
    1
    Vote Rating
    0
    grisdip is on a distinguished road

      0  

    Default


    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

Thread Participants: 2

Tags for this Thread