Results 1 to 4 of 4

Thread: can i self define a function in controller?

  1. #1
    Sencha User
    Join Date
    Oct 2010
    Posts
    80

    Question can i self define a function in controller?

    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?

    thanks

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,448

    Default

    If it is application logic then in the controller it goes.

    Code:
    Ext.define('MyApp.controller.Main', {
        extend : 'Ext.app.Controller',
    
        init: function() {
            this.control({
                'button[action=save]' : {
                    tap : this.handleSave
                },
                'button[action=cancel]' : {
                    tap : this.handleCancel
                }
            });
        },
    
        handleSave: function(btn) {
            var form = btn.up('form');
    
            if (this.doFormValidation(form)) {
                this.handleCancel(btn);
            } 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.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3
    Sencha User
    Join Date
    Oct 2010
    Posts
    80

    Default

    i see, thank for your relay.

  4. #4
    Sencha User
    Join Date
    Feb 2012
    Posts
    6

    Default

    Does this work on Ext JS 4? Because I get an error: TypeError: this.doFormValidation is not a function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •