Results 1 to 2 of 2

Thread: fireEvent

  1. #1
    Sencha User
    Join Date
    Mar 2017
    Posts
    3

    Default fireEvent

    Hi all,
    I have a form within a window, with a close and revert button. The window itsself has a close button. If I click this button another window shoud be openend where I can close the window with or without saving the form. But the fireevent does not fire! Here is my code.

    View
    Code:
    Ext.define('MyApp.view.window.User', {    
       extend: 'Ext.window.Window',
        initComponent: function() {   
        .......
        this.items = [{
                border: false,
                layout: 'fit',
                items: [{
                    xtype: 'userform',
                    record: this.record
                }]
            }];
        this.buttons = [{           
           text: 'close',            
           scope: this,           
           handler: this.handleBeforeClose
       }];  
      }
    ...
    handleBeforeClose: function() {        
         var me = this;       
         var item = me.down('form');       
         if (item.isDirty()) {           
            var confW = Ext.create('Ext.window.Window', {               
                  title: 'save',              
                  layout: 'vbox',                
                  items: [{                   
                  xtype: 'container',                   
                  margin: '10, 5, 5, 5' 
                 }, {  
                      xtype: 'container', 
                       layout: 'hbox', 
                       items: [{
                           xtype: 'button',
                            text: 'yes',
                            margin: '5, 0, 5, 5',
                            handler: function() {
                               me.down('form').fireEvent('save', me.down('form'));
                               confW.close();
                            }
                        }, { 
                           xtype: 'button', 
                           text: 'no', 
                           margin: '5, 5, 5, 5',
                           handler: function() {
                                confW.close(); 
                           }
                        }] 
                   }]
                });
                confW.on('close', me.close, me);
                confW.show(); 
           } else { 
               me.close(); 
           }
        }

    Controller

    Code:
        
    Ext.define('MyApp.controller.form.User', {
        extend: 'Ext.app.Controller',
    
        init: function() {
            this.control({
                'userform': {
                    save: this.save
                },
            })
        },
        save: function(panel) {
                  console.log('SAVE');  //This code i never used?????
        },
    Please help to execute the code in the 'save'

  2. #2
    Sencha MVP Team Member
    Join Date
    Sep 2016
    Location
    Kennewick, WA
    Posts
    153
    Answers
    15

    Default

    Code:
    me.down('form').fireEvent('save', me.down('form'));
    From your code above it would seem should have this defined on your form and not in your controller..
    Code:
      listeners: {
        save: function(panel) {
          console.log('SAVE');
        }
      }
    Right now you have your save defined in your controller. You would access that by whatever.getViewModel().getController().save(panel);

    The documentation gives two good examples of accomplishing event binding and using fireEvent.

Tags for this Thread

Posting Permissions

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