Results 1 to 3 of 3

Thread: Ext js override init component function

  1. #1
    Sencha User
    Join Date
    Dec 2013
    Posts
    41

    Default Ext js override init component function

    I am trying to override some code in the initComponent function of the Ext.window.MessageBox class. But none of the things that I change get applied. What is the problem here? Am I missing something?
    Code:
      Ext.define('hds.override.MessageBox', {     override: 'Ext.window.MessageBox',     initComponent: function() {      console.log("init component 1"); //not reached      this.callParent();       console.log("init component 2"); //not reached   }   });

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

    Default

    Are you using Ext.Msg or the like to show the messagebox expecting your override to be hit?
    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 Premium User
    Join Date
    Jul 2013
    Posts
    15

    Default The problem is that you're trying to override an instantiated singleton

    @mirkotus, by the time you what to override the singltons Ext.Msg or Ext.MessageBox their are already constructed and initialized. You're best bet is to either override Ext.window.MessageBox, create and show it or extend the class and use that. To rephrase your snippet:
    Code:
    Ext.define('hds.override.MessageBox', {
        override: 'Ext.window.MessageBox',
        initComponent: function() {
            console.log("init component 1"); //reached      
            this.callParent(arguments);  // here you might have your own init and maybe callSuper instead      
            console.log("init component 2"); // reached 
        }});
    
    
            Ext.application({
                name: 'Fiddle',
    
    
                launch: function() {
    
    
                    Ext.create('Ext.window.MessageBox').show({
                        title: 'Save Changes?',
                        multiline: true,
                        value: 'This is a very very very very very very very very very very very very very very very very very very long test',
                        msg: 'You are closing a tab that has unsaved changes.<br>Would you like to save your changes?',
                        buttons: Ext.Msg.YESNOCANCEL,
                        icon: Ext.Msg.ERROR
                    });
                }
            });

Posting Permissions

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