Ducky
01-22-2010, 11:21 AM
I am trying to display a default value (which is brought in via a Ext.Ajax.request) in a Combo Box prior to the user clicking the Down arrow to see the choices. There is a single letter Area value coming in through the Ajax request which I want to use to find an Area name in an already loaded Json data store and display the name corresponding to the code passed in. I have tried putting a listener on the Combo Box before show and before load but my Ajax request did not fire off. If I put the listener for the Ajax request on the window, it fires before the store is loaded into the combo box so all I get is the code itself. Here below is my code:
Ext.onReady(function() {
new Ext.Window({
listeners: {
beforeshow: function(){
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
action: 'getdefault',
pgm: 'CHGAREA'
},
success: function(response){
var check = response.responseText;
if (check) {
var data = Ext.util.JSON.decode(response.responseText);
}
if (data.SUCCESS == '1') {
Ext.getCmp('dArea').setValue(data.ARAREA);
}
else {
vvShowError('ERROR OCCURED', 'Current work area default not found.');
}
}
})
}
},
title: 'Change Work Area',
iconCls:'application_view_detail',
closable:false,
resizable:false,
x:100,
y:150,
layout:'table',
bodyStyle: 'padding:20px',
height:100,
width:450,
items: [{
xtype: 'combo',
emptyText: 'Select the work area',
labelSeparator: ' ',
id: 'dArea',
triggerAction: 'all',
displayField: 'ARNAME',
valueField: 'ARAREA',
store: new Ext.data.JsonStore({
autoLoad: true,
url: 'vvcall.pgm',
baseParams: {
pgm: 'CHGAREA',
action: 'load'
},
root: 'MLPAREA',
fields: ['ARAREA', 'ARNAME']
}),
listeners: {
select: {
fn: function(){
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
action: 'save',
pgm: 'CHGAREA',
narea: Ext.getCmp('dArea')
}
})
}
}
}
}]
}).show();
});
Ext.onReady(function() {
new Ext.Window({
listeners: {
beforeshow: function(){
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
action: 'getdefault',
pgm: 'CHGAREA'
},
success: function(response){
var check = response.responseText;
if (check) {
var data = Ext.util.JSON.decode(response.responseText);
}
if (data.SUCCESS == '1') {
Ext.getCmp('dArea').setValue(data.ARAREA);
}
else {
vvShowError('ERROR OCCURED', 'Current work area default not found.');
}
}
})
}
},
title: 'Change Work Area',
iconCls:'application_view_detail',
closable:false,
resizable:false,
x:100,
y:150,
layout:'table',
bodyStyle: 'padding:20px',
height:100,
width:450,
items: [{
xtype: 'combo',
emptyText: 'Select the work area',
labelSeparator: ' ',
id: 'dArea',
triggerAction: 'all',
displayField: 'ARNAME',
valueField: 'ARAREA',
store: new Ext.data.JsonStore({
autoLoad: true,
url: 'vvcall.pgm',
baseParams: {
pgm: 'CHGAREA',
action: 'load'
},
root: 'MLPAREA',
fields: ['ARAREA', 'ARNAME']
}),
listeners: {
select: {
fn: function(){
Ext.Ajax.request({
url: 'vvcall.pgm',
params: {
action: 'save',
pgm: 'CHGAREA',
narea: Ext.getCmp('dArea')
}
})
}
}
}
}]
}).show();
});