View Full Version : can i self define a function in controller?

23 Nov 2011, 12:34 AM
i implement a page in MVC pattern, in my controller i want to call a self-defined function, but when i call it, catch exception as following:

Uncaught ReferenceError: deleteOneNumber is not defined.

deleteOneNumber: function(val) {
return val;

where can i place self-defined function in??? in controller, model, or view?


23 Nov 2011, 9:53 AM
If it is application logic then in the controller it goes.

Ext.define('MyApp.controller.Main', {
extend : 'Ext.app.Controller',

init: function() {
'button[action=save]' : {
tap : this.handleSave
'button[action=cancel]' : {
tap : this.handleCancel

handleSave: function(btn) {
var form = btn.up('form');

if (this.doFormValidation(form)) {
} else {
Ext.Msg.alert('Error', 'There was an error!');

handleCancel: function(btn) {
var form = btn.up('form');

//close floating panel

doFormValidation: function(form) {
var isValid = false;

//do some validation

return isValid;

So you can see, doFormValidation isn't used anywhere except within handleSave so it's a custom function. handleCancel is a hybrid... it's used as an event listener but also as a custom function.

24 Nov 2011, 7:15 PM
i see, thank for your relay.

6 Sep 2012, 12:59 AM
Does this work on Ext JS 4? Because I get an error: TypeError: this.doFormValidation is not a function