My current issue relates to showing an initial value in an ExtJS combobox relating to an employee's department in an employee detail page.
The page retrieves the employee information via PHP, so all the references to the employee are done through PHP echo (the site uses CodeIgniter, which may confuse some; it just simplifies some of the input but works in the same way as normal PHP), i.e.
var formPanel = Ext.create('Ext.form.Panel', {
title: 'User Details',
width: 300,
renderTo: Ext.get('details'),
store: userStore,
defaultType: 'textfield',
items:
[
{
fieldLabel:'User Name',
name: 'UserName',
allowBlank: false,
value: '<?php echo $Employee->UserName; ?>'
},
//More details in similar format etc.
]
});
There is a section for the departments, to be handled through a combobox, to list all departments; there is nothing fancy (I believe), it just lists all the departments:
Ext.define('DeptModel', {
extend: 'Ext.data.Model',
fields: [
{name:'Id', type: 'int'},
{name:'Name', type: 'string'}
]
});
var deptStore = Ext.create('Ext.data.Store', {
model:'DeptModel',
autoload: true,
proxy: {
// load using HTTP
type: 'ajax',
url: '<?= $site_url ?>Settings/JSON/Departments',
reader: {
type: 'json',
model: 'DeptModel'
}
}
});
The formPanel above then references the deptModel/deptStore in a comboBox:
{
fieldLabel:'Department',
xtype:'combo',
name:'Department',
forceSelection: true,
typeAhead: true,
allowBlank: false,
emptyText: 'Choose a Department',
store: deptStore,
displayField: 'Name',
valueField: 'Id'
}
The above combobox renders correctly and provides all the departments. Attempts to initialise the combobox with a value, however, have not worked, ranging from no change in the combobox to creating errors that stop the page rendering. I have looked at the following:
value: 5 // or any integer
value: '5' // or any string
value: <?php echo $Employee->DepartmentId ?> // or any PHP reference like those that work for the textfields e.g. the User Name above - DepartmentId has been checked to be an integer
value: '<?php echo $Employee->DepartmentId ?>' // stringifying the PHP reference
value: 'Accounts'
I have also looked at the numerous posts relating to loading stores after rendering, setting values on store loading, setting values on render, setting values before the formPanel code; quite frankly, none have worked, and most refer to setting the value to the first in the list which doesn't treat my particular issue.
Ideally, I want to simply state
value: <?php echo $Employee->DepartmentId ?>
to have the combobox display the relevant department (i.e. "Accounts") when the employee's details are displayed in the form on page load.
Where am I going wrong? Why does value: {value} not do anything in practice? Can anyone provide a simple explanation as to the correct form of inserting a combobox into a formPanel that allows for the initial value in said combobox to be picked on page load, if the current implementation is somehow incorrect?

loadevent, to fire off some code that sets the value of the combobox. Basically, you need to make sure the data is loaded before setting the value. - forgivenson