PDA

View Full Version : adding store to combo field



nimaous
25 May 2012, 8:53 AM
Hi
In my Edit.js when I add store to my combo filed I got this error :
Uncaught TypeError: Cannot call method 'on' of undefined


below is my Edit.js :


Ext.define('WAITER.view.waiter.Edit', {
extend: 'Ext.window.Window',
alias: 'widget.waiteredit',


requires: ['Ext.form.Panel', 'Ext.form.field.Text', ],

stores: ['Customers', 'Waiters'],
title: 'Edit Waiter',
layout: 'fit',
autoShow: true,
width: 280,

iconCls: 'icon-user',


initComponent: function() {
this.items = [{
xtype: 'form',
padding: '5 5 0 5',
border: false,
style: 'background-color: #fff;',

fieldDefaults: {
anchor: '100%',
labelAlign: 'left',
allowBlank: false,
combineErrors: true,
msgTarget: 'side'
},


items: [{
xtype: 'textfield',
name: 'id',
fieldLabel: 'id',
hidden: true
},


{
name: 'customer',
xtype: 'combo',
store: 'Customers',
fieldLabel: 'customer',

},


{
xtype: 'textfield',
name: 'destination',
fieldLabel: 'destination'
}, {
xtype: 'datefield',
name: 'from_date',
fieldLabel: 'from_date'
}, {
xtype: 'datefield',
name: 'to_date',
fieldLabel: 'to_date'
}, {
xtype: 'textfield',
name: 'from_cost',
fieldLabel: 'from_cost'
}, {
xtype: 'textfield',
name: 'to_cost',
fieldLabel: 'to_cost'
}, {
xtype: 'textfield',
name: 'hotel_stars',
fieldLabel: 'hotel_stars'
}, {
xtype: 'textfield',
name: 'airline',
fieldLabel: 'airline'
}, {
xtype: 'textfield',
name: 'sure',
fieldLabel: 'sure'
}, {
xtype: 'textfield',
name: 'visited',
fieldLabel: 'visited'
},


]
}];

this.dockedItems = [{
xtype: 'toolbar',
dock: 'bottom',
id: 'buttons',
ui: 'footer',
items: ['->',
{
iconCls: 'icon-save',
itemId: 'save',
text: 'Save',
action: 'save'
}, {
iconCls: 'icon-reset',
text: 'Cancel',
scope: this,
handler: this.close
}]
}];


this.callParent(arguments);
}
});


and also I'm sure about the store/Customers.js which work properly

Tim Toady
25 May 2012, 9:56 AM
Move stores to your controller

scottmartin
25 May 2012, 10:04 AM
Place the stores in your controller:
stores: ['Customers', 'Waiters'],

Scott.

nimaous
25 May 2012, 10:13 AM
I did this
but when I add Customers store to my controller and when I refresh the page nothing appeared

nimaous
25 May 2012, 10:15 AM
this is my Controller.js



Ext.define('WAITER.controller.Waiters', {
extend: 'Ext.app.Controller',


stores: ['Waiters','Customers'],




models: ['Waiter','Customer'],


views: ['waiter.Edit', 'waiter.List'],


refs: [{
ref: 'waitersPanel',
selector: 'panel'
},{
ref: 'waiterlist',
selector: 'waiterlist'
}
],


init: function() {
this.control({
'waiterlist dataview': {
itemdblclick: this.editUser
},
'waiterlist button[action=add]': {
click: this.editUser
},
'waiterlist button[action=delete]': {
click: this.deleteUser
},
'waiteredit button[action=save]': {
click: this.updateUser
}
});
},


editUser: function(grid, record) {
var edit = Ext.create('WAITER.view.waiter.Edit').show();

if(record){
edit.down('form').loadRecord(record);
}
},

updateUser: function(button) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues();
if (values.id > 0) {

record.set(values);
} else {

record = Ext.create('WAITER.model.Waiter');
record.set(values);
//record.setId(0);
this.getWaitersStore().add(record);
}

win.close();
this.getWaitersStore().sync();
},

deleteUser: function(button) {

var grid = this.getWaiterlist(),
record = grid.getSelectionModel().getSelection(),
store = this.getWaitersStore();


store.remove(record);
this.getWaitersStore().sync();
}
});

Tim Toady
25 May 2012, 11:14 AM
What do you mean by "nothing appeared"
The entire page was white? The grid is empty? Were there any errors?

Also, please use code tags around your code to make it more readable

aryanet
25 May 2012, 1:44 PM
You should check your server's log and see what's going on on the backend. If there is something wrong with Model.js and it sticks in loading that you may have probably some mistakes in Customers store file.