PDA

View Full Version : Populate ComboBox with Reader of FormPanel



test45
11 Oct 2010, 5:03 AM
Hello all,
I need your help.

I would like to know if a ComboBox is able to populate itself with reader's data of FormPanel.

I have to do this to have the less queries on my database.

Thanks in advance. Sorry for my poor english...

Nb:


var formEditItemPdv = new Ext.form.FormPanel({
url: "/action_edit",
frame: true,
width: 400,
height: 400,
labelAlign: "right",
waitMsgTarget: true,
defaults: {
anchor: "100%",
blankText: "Required",
autoHeight: true
},
reader : new Ext.data.XmlReader({
record : "result",
success: "@success"
}, [
{name: "ite_id", mapping:"ITE_ID"},
{name: "ite_libelle", mapping:"ITE_LIBELLE"},
{name: "ite_libelle_moyen", mapping:"ITE_LIBELLE_MOYEN"},
{name: "ite_libelle_court", mapping:"ITE_LIBELLE_COURT"},
{name: "ite_flag", mapping:"ITE_FLAG"},
{name: "pdv_id", mapping:"PDV_ID"},
{name: "pdv_libelle", mapping: "PDV_LIBELLE"},
{name: "pdv_commentaire_fo", mapping: "PDV_COMMENTAIRE_FO"},
{name: "conditionnement", mapping: "CONDITIONNEMENT"}
]
),
defaultType: "textfield",
items: [{
fieldLabel: "Libellé",
name: "ite_libelle",
allowBlank: false,
maxLength: 150,
},{
fieldLabel: "Libellé moyen",
name: "ite_libelle_moyen",
allowBlank: false,
maxLength: 100
},{
fieldLabel: "Libellé court",
name: "ite_libelle_court",
allowBlank: false,
maxLength: 50
},{
xtype: "textarea",
fieldLabel: "Commentaire",
name: "pdv_commentaire_fo",
allowBlank: false,
maxLength: 1000
},{
new Ext.form.ComboBox({
/* need something... mapping with "conditionnement" */
}),{
xtype: "hidden",
name: "ite_id"
}]
});

formEditItemPdv.addButton('Load', function(){
formEditItemPdv.getForm().load({url:"/load_info", waitMsg: formWaitMsg, params: {ite_id: 7669}});
});


Example of short xml:




7669

4918
Libelle
Libelle2
Libelle3


Libelle4

Comment


1
Cond1


2
Cond2

Condor
11 Oct 2010, 5:40 AM
Configure your ComboBox, so it can read your XML and override the form setValues() method to first load the combobox before setting the values, e.g.

setValues: function(values) {
combobox.store.loadData(this.reader.xmlData);
this.constructor.prototype.setValues.call(this, values);
}

test45
12 Oct 2010, 5:55 AM
Thanks I post my code...
It selects the right field in combobox, too.

Combobox


var comboBox = new Ext.form.ComboBox({
store: new Ext.data.Store({
remoteSort: false,
reader: new Ext.data.XmlReader ({
record: "rowCOND",
idPath: "COND_ID"
},[
{name: "COND_ID", mapping: "COND_ID", type: "int"},
{name: "COND_LIBELLE_MOYEN", mapping: "COND_LIBELLE_MOYEN", type: "string"}
]
)
}),
typeAhead: true,
lazyRender: true,
forceSelection: true,
triggerAction: "all",
mode: "local",
selectOnFocus: true,
fieldLabel: "Cond",
valueField: "COND_ID",
displayField: "COND_LIBELLE_MOYEN",
hiddenName: "cond_id",
editable: false
});

Form


var formEditItemPdv = new Ext.form.FormPanel({
url: "/edit_item",
frame: true,
width: widthWindowForm,
height: heightWindowForm,
labelAlign: "right",
waitMsgTarget: true,
bodyStyle:'padding:15px',
defaultType: "textfield",
defaults: {
anchor: "100%",
blankText: blankText,
maxLengthText: maxLengthText,
autoHeight: true
},
reader : new Ext.data.XmlReader({
record : "result",
success: "@success"
}, [
{name: "ite_id", mapping:"ITE_ID"},
{name: "ite_libelle", mapping:"ITE_LIBELLE"},
{name: "ite_libelle_moyen", mapping:"ITE_LIBELLE_MOYEN"},
{name: "ite_libelle_court", mapping:"ITE_LIBELLE_COURT"},
{name: "ite_flag", mapping:"ITE_FLAG"}
]
),
items: [{
fieldLabel: "Libellé",
name: "ite_libelle",
allowBlank: false,
maxLength: 150,
},{
fieldLabel: "Libellé moyen",
name: "ite_libelle_moyen",
allowBlank: false,
maxLength: 100
},{
fieldLabel: "Libellé court",
name: "ite_libelle_court",
allowBlank: false,
maxLength: 50
},
comboBox,
{
xtype: "hidden",
name: "ite_id"
}],
setValues: function(values) {
comboBox.store.loadData(this.reader.xmlData);
comboBox.setValue(Ext.DomQuery.selectNumber("/resultCOND/rowCOND:has(COND_SELECTED:nodeValue(true))/COND_ID", comboBox.store.reader.xmlData.documentElement));
this.constructor.prototype.setValues.call(this, values);
}
});


[CODE]



1
Blle 75 cl (1x75)
false


4
Caisse bois 12 blles (12x75 (cb))
false


13
Dble mag. 300 cl (1x300)
true



6194
Clerc Milon - 2001 - double magnum (300 cl) - 1x300