PDA

View Full Version : Ext.Combobox & XML Store - Select Problem



f.sauter
29 Jul 2009, 4:40 AM
Hi everyone,

i tried to set up a combo box using a xml data store.

the view works fine.. but whenever I select an option, the value from the combobox jumps to the first Id (in my case ".asia2").

JS Code:


Ext.EasyForm.FormFields.TopLevelDomainCheckbox = Ext.extend(Ext.form.ComboBox, {
allowBlank : false,
valueField: 'id',
displayField:'short',
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
selectOnFocus:true,
dataStorePath: 'tlds.xml',
initComponent : function(config) {
Ext.apply(this, {
store: new Ext.data.Store({
url: this.dataStorePath,
reader: new Ext.data.XmlReader({
record: 'tld',
id: 'id',
totalRecords: '@total'
}, ['short'])
})
});
Ext.EasyForm.FormFields.TopLevelDomainCheckbox.superclass.initComponent.apply(this, arguments);
},
onRender : function() {
this.store.load();
Ext.EasyForm.FormFields.TopLevelDomainCheckbox.superclass.onRender.apply(this, arguments);
}
});
XML File ('tlds.xml'):


<?xml version="1.0" encoding="UTF-8"?>
<tlds>
<tld><id>0</id><short>asia2</short></tld>
<tld><id>1</id><short>asia</short></tld>
<tld><id>2</id><short>at</short></tld>
<tld><id>3</id><short>biz</short></tld>
<tld><id>4</id><short>ch</short></tld>
<tld><id>5</id><short>cn</short></tld>
<tld><id>6</id><short>co.at</short></tld>
<tld><id>7</id><short>co.uk</short></tld>
</tlds>

Can you see something suspicious? Any suggestions..? Any links that might help me?

*using Ext 3.0.0 + Firebug 1.4.1 (no errors)

Animal
29 Jul 2009, 4:48 AM
you have no field named "id"

f.sauter
29 Jul 2009, 5:19 AM
you have no field named "id"


Thanks for the fast support/tip, has brought me to the solution.



reader: new Ext.data.XmlReader({
record: 'tld',
id: 'id'
},
Ext.data.Record.create([
{name: 'id'},
{name: 'short'}
])
)

f.sauter
11 Aug 2009, 2:44 AM
Hi all,

just another short Question:

I want to set the default value of my combobox to the first node of my xml file.


this.select(0);
.. should be the best function? This mostly causes in an error. (e.g. "this.view is undefined")


Can you just give me a hint, where I must enter the code? The same in onRender/constructor does not work either.


Ext.EasyForm.FormFields.TopLevelDomainCheckbox = Ext.extend(Ext.form.ComboBox, {
allowBlank : false,
valueField:'id',
displayField:'short',
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
selectOnFocus:true,
dataStorePath: 'locales/de_DE/tlds.xml',
initComponent : function(config) {
Ext.apply(this, {
store: new Ext.data.Store({
autoDestroy: true,
autoLoad: true,
url: this.dataStorePath,
reader: new Ext.data.XmlReader({
record: 'tld',
id: 'id'
},
Ext.data.Record.create([
{name: 'id'},
{name: 'short'}
])
)
})
});
Ext.EasyForm.FormFields.TopLevelDomainCheckbox.superclass.initComponent.apply(this, arguments);
}
});

Animal
11 Aug 2009, 2:57 AM
Use



function getTopLevelDomainCheckbox() {
return new Ext.form.ComboBox({
allowBlank : false,
valueField:'id',
displayField:'short',
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
selectOnFocus:true,
lazyInit: false,
store: new Ext.data.Store({
autoDestroy: true,
autoLoad: true,
url: 'locales/de_DE/tlds.xml',
reader: new Ext.data.XmlReader({
record: 'tld',
id: 'id'
}, Ext.data.Record.create([
{name: 'id'},
{name: 'short'}
])
)
});
}

f.sauter
11 Aug 2009, 3:47 AM
hm okay this solution does not work. combobox yes, data loaded yes, default selection no..

var exampleBox = getTopLevelDomainCheckbox();

new Ext.form.FormPanel({...
items: [...exampleBox..]
...});
exampleBox.select(0);
No error message in firebug.

Condor
11 Aug 2009, 3:50 AM
Do NOT use select or selectByValue!

Use setValue after the store is loaded.

f.sauter
11 Aug 2009, 4:13 AM
almost thought... how about here::


Config exampleBox same as before only:
autoDestroy: false,


exampleBox.setValue(exampleBox.getStore().getAt(0).get('id'));-> exampleBox.getStore().getAt(0) is undefined (:|

Condor
11 Aug 2009, 4:19 AM
ComboBox doesn't have a 'getStore' method; it has a 'store' property.

f.sauter
11 Aug 2009, 4:43 AM
ComboBox doesn't have a 'getStore' method; it has a 'store' property.

Ext 3.0 - API Documentation -> Ext.form.Combobox -> Public Mehotds -> getStore (http://extjs.com/forum/../deploy/dev/docs/source/Combo.html#method-Ext.form.ComboBox-getStore)()
Have I misunderstood something :-|?

exampleBox.store.getAt(0) is undefined same again.

aeiou
9 Sep 2009, 6:40 AM
Ext 3.0 - API Documentation -> Ext.form.Combobox -> Public Mehotds -> getStore (http://extjs.com/forum/../deploy/dev/docs/source/Combo.html#method-Ext.form.ComboBox-getStore)()
Have I misunderstood something :-|?

exampleBox.store.getAt(0) is undefined same again.

:)) funny, i've got the same 'trap' as well. wrong docs or anything missing? anybody may provide light to this issue?

thanks

w i l l y

ps: on the other hand, if you have a reference to the combobox's store, you can use the methods as usual

aeiou
9 Sep 2009, 7:14 AM
:)) funny, i've got the same 'trap' as well. wrong docs or anything missing?
actually i guess is the former. Searching for this issue i found
http://www.extjs.com/forum/showthread.php?t=66156&highlight=combobox+getStore and, opposite to the documentation, it seems the Ext.form.Combobox component has a (undocumented) store property which returns the store for that combo. should that be reported as a documentation bug? I'm not sure as I am mostly new to this forum and I dunno the procedures.

regards