1. #1
    Sencha User
    Join Date
    Mar 2012
    Posts
    3
    Vote Rating
    0
    gardner is on a distinguished road

      0  

    Default Unanswered: Event handling in MVC text fields?

    Unanswered: Event handling in MVC text fields?


    I am unclear on the preferred method of event handling when trying to apply an MVC model. The button examples show a button configured like this:

    View item:
    Code:
      {
          text: 'Save',
          action: 'save'
      }
    Controller code:
    Code:
    'useredit button[action=save]': {
        click: this.updateUser
       }
    Which matches the concept of pushing all logic out of the view into the controller. The text field examples, however, look like this, with everything in the view:
    Code:
    {
        fieldLabel: 'Field 2',
        name: 'field2',
        listeners: {
            specialkey: function(field, e) {
                if( e.getKey() == e.ENTER) {
                     var form = field.up('form').getForm();
                     form.submit();
               }
       }
    }
    This lets you handle the different events differently, but leaves teh code in the view. Is this accepted practice? One of my developers has tried this approach for text fields, but I am not sure I am comfortable with it:

    View item:
    Code:
    {
        xtype: 'textfield',
        fieldLabel: 'Phone',
        name: 'phone',
        itemId: 'phone',
        action: 'hitEnter'
    }
    Controller code:
    Code:
    {
        'targetForm textfield[action=hitEnter]' : {
              specialkey: this.hitEnter
    }
    In a related question, I have not found documentation on exactly how you specify actions. Can you just put in any string and use it as in the example above?

    Thanks. I am a newbie on ExtJS, so no reply is too basic.

    - Gardner
    Last edited by jratcliff; 17 May 2012 at 5:47 PM. Reason: added code tags

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,754
    Answers
    3461
    Vote Rating
    827
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    We don't force people to use MVC so you can use listeners on the view itself but all those listeners are available to be listened to in the controller.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2012
    Posts
    3
    Vote Rating
    0
    gardner is on a distinguished road

      0  

    Default


    Mitchell,

    Thanks for the reply, but I am not sure if you mean that they last code example is the preferred method, or if we should explicitly have some sort of listener code in the controller. Is the "action" keyword in the view what we are supposed to do for all events in MVC?

    A code fragment would probably be helpful.

    - Gardner

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,910
    Answers
    655
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    MVC is for you to organize your code. If you want to use the MVC convention, then use the controller for your event handling to maintain our pattern.

    This does not mean you are forced to and can certainly place a listener in your view if you prefer.

    Regards,
    Scott.

  5. #5
    Sencha Premium Member
    Join Date
    Jun 2012
    Location
    San Jose, California
    Posts
    70
    Answers
    1
    Vote Rating
    0
    nhan is on a distinguished road

      0  

    Default Looking for more examples in MVC event handling in ExtJS 4

    Looking for more examples in MVC event handling in ExtJS 4


    Does anyone have examples on this? I have multiple pages. How do I pass an event to the controller level and how one page listens to another page's event?
    Thanks,
    nhan