PDA

View Full Version : Ext.form.ComboBox


GordS
03-26-2010, 04:59 PM
I have just created a program using AutoCode file maintenance option. I want to add some select lists too some of the fields when adding or editing the records. Some of the select fields data will come from other data files and some will be like Y or N options. I am looking for a good example of this. I tried to review vvOpts but it is has so many things going on that I am not sure if this will help me.

My internet research tells me I should be using a JSON data store but this program does not appear to be using it on the ComboBox logic. But it could be that I am just missing something.

In the meantime I will keep searching. I find something I let everybody else know what I found.

sean.lanktree
03-26-2010, 05:18 PM
You are correct in that you will need a new JSON store to hold the values of your combobox.

Suppose you are going to take an existing "textfield" and change it to a combo box instead...


xtype: 'combo',
id: 'myCombo',
fieldLabel: 'A combo box',
triggerAction: 'all',
store: new Ext.data.JsonStore({
url : 'vvcall.pgm',
root: 'FILEXXX', // I usually use the name of the file where the data is
fields: ['FIELDA'], // the name of the field that will be returned
baseParams: {
action: 'getMyData',
pgm: 'PGMXXX' //the name of the rpg program
}
})


Now the RPG....


select;
when post_Action = 'getMyData';
SendBackComboData();
endsl;


** SendBackComboData procedure
p SendBackComboData
d pi
/free
vvOut.rootName = 'FILEXXX';
vvOut.execSqlToJson(vvOut:'select fielda from filexxx');

GordS
03-27-2010, 04:42 PM
Sean - I am close to getting it too work. Details, details, details.

Here is the javascript code that I added.
var BCCURRENCY
var BCDESCRIPT
xtype:'combo',
id:'add_CMCURRENCY',
fieldLabel:'Currency',
triggerAction: 'all',
store: new Ext.data.JsonStore({
url : 'vvcall.pgm',
root: 'BMCURRLA',
fields: [BCCURRENCY,BCDESCRIPT],
baseParams: {
action: 'getComboCurr',
pgm: 'apmcust'
}
})

Here is the RPG code

elseif post_Action='getComboCurr';
SendBackComboCurr();
p SendBackComboCurr...
p b
d pi
/free
vvOut.rootName = 'BMCURRLA';
vvOut_execSqlToJson(vvOut:'select BCCURRENCY, BCDESCRIPT from BMCURRLA');
/end-free
p e

I am getting the following response in Firebug.

{"BMCURRLA":[{"BCCURRENCY":"Cdn","BCDESCRIPT":"Canadian Dollars"},{"BCCURRENCY":"USD","BCDESCRIPT":"U.S. Dollars"},{"BCCURRENCY":"Eur","BCDESCRIPT":"Euros"},{"BCCURRENCY":"BP","BCDESCRIPT":"British Pounds"}],"totalCount":4}

I get down arrow on the currency field. When I click on it I see LOADING, but nothing shows up. What detail did I miss in your response that ties it all together?

sean.lanktree
03-27-2010, 07:14 PM
Try adding the following configuration options to the combobox...


xtype: 'combo',
displayField: 'BCDESCRIPT',
valueField: 'BCCURRENCY'


This means that the user will see/select the description field. But when you post the selection (to your RPG program), it will pass BCCURRENCY.

GordS
03-28-2010, 01:31 PM
Sean - I made the change you suggested but I still get the same result as described before. Here is my latest version of the JavaScript code.

xtype:'combo',
id:'add_CMCURRENCY',
fieldLabel:'Currency',
triggerAction: 'all',
emptyText: 'Select Currency...',
valueField: BCCURRENCY,
displayField: BCDESCRIPT,
store: new Ext.data.JsonStore({
url : 'vvcall.pgm',
root: 'BMCURRLA',
fields: [BCCURRENCY,BCDESCRIPT],
baseParams: {
action: 'getComboCurr',
pgm: 'apmcust'
}
})

sean.lanktree
03-28-2010, 03:45 PM
Surround your field names in single quotes...that must be the problem.


fields: ['BCCURRENCY','BCDESCRIPT']

GordS
03-29-2010, 08:46 AM
Sean - You are right about that. As soon as I enclosed them in quotes I was able to get rid of where I defined the variables. But I am still get the same results as previously outlined. Updated code here.
xtype:'combo',
id:'add_CMCURRENCY',
fieldLabel:'Currency',
triggerAction: 'all',
emptyText: 'Select Currency...',
valueField: 'BCCURRENCY',
displayField: 'BCDESCRIPT',
store: new Ext.data.JsonStore({
url : 'vvcall.pgm',
root: 'BMCURRLA',
baseParams: {
action: 'getComboCurr',
pgm: 'apmcust',
fields: ['BCCURRENCY','BCDESCRIPT']
}
})

sean.lanktree
03-29-2010, 10:04 AM
Your "fields" config option is at the wrong spot. "fields" is a configuration of the data store and it currently exists as a parameter for "baseParams". Move it as follows:


store: new Ext.data.JsonStore({
url: 'vvcall.pgm',
fields: [.......,

})

sean.lanktree
03-29-2010, 10:21 AM
By the way, I see that my original post of the code had fields in the wrong spot...sorry about that. Going to edit that post so nobody else gets confused by that.

GordS
03-29-2010, 12:55 PM
Sean - That worked. The devil is in the details. I will do a more thorough test later today or sometime tomorrow to make sure the back end file gets updated properly. I will update you then. Thanks.

GordS
03-29-2010, 02:33 PM
Sean - We were able to do a test and the value selected from the ComboBox gets updated back in the database. Thanks for your help.