PDA

View Full Version : Problem loading combobox at the beginning



Oberdan
23 Oct 2007, 10:01 AM
Hello all,

Well, seems that after reading a lot of documentation, things are finally working (more or less). Still, I'm having some problems with loading Ajax data inside a combobox and setting a default value.

I have a local Apache servert running. All loads fine, but the content of the "ADMs" combobox is fetched only when I open it, and not when the form is shown. I've tried using "autoload:true", "lazyInit:false", ADMs.load() just after creating it. and so on, but none of these worked.

When I call ADMs.load(), the XML is fetched, but then when I click the combo it is fetched again....

I can't load all the data at once the way it is in the XML form example, since the second combo (and some others I'll add) is filled depending on what is selected on the first. Which is the best way of doig this kind of thing? Should I create e

[CODE]// create namespace
Ext.namespace('BaseNameSpace');

// create application
BaseNameSpace.App = function() {
// do NOT access DOM from here; elements don't exist yet

// private variables

// private functions

// public space

var Viewport;
var TopPanel;
var LeftPanel;
var CenterPanel;

var ItemsForm;

return {
// public properties, e.g. strings to translate

// public methods
init: function() {

var ADMs = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: '/test/xml/ADMs.xml' ,
method:'GET',
text:'Loading...'
}),
reader: new Ext.data.XmlReader({record: 'ADM'},['value','text']),
});

ItemsForm = new Ext.FormPanel({
labelWidth: 100, // label settings here cascade unless overridden
region:'center',
id:'form-panel',
el:'form-div',
frame:true,
title: 'Relat

tryanDLS
23 Oct 2007, 10:11 AM
This new tutorial (http://extjs.com/learn/Tutorial:Linked_Combos_Tutorial_for_Ext_2) might given you some ideas about handling linked combos.

Oberdan
23 Oct 2007, 10:20 AM
I didn't see that one... It is indeed very useful when dealing with linked combos, but does not deals with Ajax, so I still can't figure out why my combo is not filled at the beginning...

Thanks!

Oberdan
23 Oct 2007, 5:35 PM
Hello all again,

I tried to reduce the actual code to the minimum, to make it easy to find where is the mistake, and I got this:



var Recs = new Ext.data.Record.create( [{name:'code', mapping:'value'},
{name:'description', mapping:'text'}] );
var ADMs = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url:'/test/xml/ADMs.xml',
method:'GET',
text:'Loading...'
}),
reader: new Ext.data.XmlReader( {record: 'ADM'} , Recs ),
autoLoad:true
});

var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
url:'',
renderTo:document.body,
frame:true,
title: 'Simple Form',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 230},
defaultType: 'textfield',
items: [
new Ext.form.ComboBox({
id:'formCombo',
store: ADMs,
autoLoad:true,
editable:false,
fieldLabel:'ADM',
hiddenName:'ADMValue',
valueField:'code',
displayField:'description',
triggerAction:'all'
}),
{
fieldLabel: 'Email',
name: 'email',
vtype:'email'
}
],

buttons: [{text: 'Save', id:'formButton'}]
});



And I changed the XML to:

[CODE]
<?xml version="1.0" encoding="ISO-8859-1"?>
<AMDList>
<ADM>
<value>USM50</value>
<text>USMARC Sample Catalogs</text>
</ADM>
<ADM>
<value>PUC50</value>
<text>Pontif

Oberdan
24 Oct 2007, 11:04 AM
Well, after reading a ton of previous posts and struggling during two days with this, I think I'm getting more clues. My problem was (and still is) that the combo inside the form only load its data when I click the trigger, and I want it to be loaded just after the form is rendered. Even if the Store is already loaded, the combo makes another GET request when I click it. Using this code:



var Recs = new Ext.data.Record.create( [{name:'code', mapping:'value'},
{name:'description', mapping:'text'}] );
var ADMs = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({ url:'/test/xml/ADMs.xml',
method:'GET',
text:'Loading...'}),
reader: new Ext.data.XmlReader( {record:'ADM'} , Recs ),
autoLoad:true
});

var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
id:'TestForm',
renderTo:document.body,
frame:true,
title: 'Simple Form',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 230},
defaultType: 'textfield',
items: [
new Ext.form.ComboBox({
id:'formCombo',
store: ADMs,
editable:false,
fieldLabel:'ADM',
hiddenName:'ADMValue',
valueField:'code',
displayField:'description',
lazyInit:false,
triggerAction:'all'
})
],
buttons: [{text: 'Check', id:'formButton'}]
});

Ext.getCmp('formCombo').focus();


And the same XML, I got the form that is attached to this message.

So I already have the content inside the combo. If there is data in the store, why the Combo repeats the GET request if I click the trigger? Is there a simple way of setting the initial value of the combo as the first record inside the store?

Santacruz
25 Oct 2007, 2:45 AM
Same problem solved http://extjs.com/forum/showthread.php?p=77882#post77882

RobbyRacoon
6 Nov 2007, 10:20 AM
That doesn't seem to solve the problem the OP had, which is unfortunate since I have similar requirements and am having trouble locating the necessary information on these forums :(

tryanDLS
6 Nov 2007, 11:25 AM
You don't have a mode specified, so it defaults to 'remote'. Try mode:'local'

joshuabco
30 Oct 2008, 7:55 AM
with mode:'local' works... =D>