user2375809
user2375809

Reputation: 419

Sencha Touch 2 Controller init/launch doesn't fire

The code is below.

All I am trying to do is to load Login view from my Login controller. However, I found that the Login controller is not loaded properly. Neither launch() nor init() is called. Can any one kindly help me out?

Thanks in advance!!

app/app.js

Ext.Loader.setConfig({
  disableCaching: false,
  enabled: true
});

Ext.application({
  name: 'KangasK',
  models: [],
  stores: [],
  controllers: [
    'Login'
  ],
  views: [
  ],

  launch: function() {
    alert('launch app');
  }

});

app/controller/Login.js

Ext.define('KangasK.controller.Login', {
  extend: 'Ext.app.Controller',
  views: ['Login'],
  stores: [],
  config: {
    refs: {
      loginBtn: '#loginBtn'
    },
    control: {
      loginBtn: {
        tab: 'login'
      }
    },

    init: function() {
      alert('init')
    },

    launch: function() {
      alert('launch login');
    }
  }

});

app/view/Login.js

Ext.define('KangasK.view.Login', {
  extend: 'Ext.form.Panel',
  alias: 'widget.loginview',
  config: {
    items: [
      {
        xtype: 'fieldset',
        title: 'Login',
        items: [
          {
            xtype: 'textfield',
            placeHolder: 'Username',
            itemId: 'username',
            name: 'username',
            required: true
          },
          {
            xtype: 'passwordfield',
            placeHolder: 'Password',
            itemId: 'password',
            name: 'password',
            required: true
          }
        ]
      },
      {
        xtype: 'button',
        itemId: 'logInButton',
        ui: 'action',
        padding: '10px',
        text: 'Login'
      }
    ]
  }
});

PS: in the browser it shows app/controller/Login.js is loaded, but app/view/Login.js is not.

Upvotes: 0

Views: 1590

Answers (1)

user2375809
user2375809

Reputation: 419

I figured it out myself...

init and launch shouldn't be inside config: {}

this works:

Ext.define('KangasK.controller.Login', {
  extend: 'Ext.app.Controller',
  config: {
    views: ['Login'],
    stores: [],
    refs: {
      loginBtn: '#loginBtn'
    },
    control: {
      loginBtn: {
        tab: 'login'
      }

    }
  },
  init: function() {
    console.log('init')
  },

  launch: function() {
    console.log('launch login');
  }
});

Upvotes: 1

Related Questions