PDA

View Full Version : combo problrm



sidd
21 Jul 2009, 10:03 PM
Hi,

I am huving a problem with the combo. its not taking the valueField properly. My value field is agentid but when i m clicking the submit button it is always giving an alert of the agentinfo only even after submition of the from its passing agentinfo as combo value.

Plz help.

#HTML
<form action="abcd.html" method="get">
<input type="text" id="local-states" size="20"/>
<input type="submit" value="Submit" onclick="doClick()"/>
</form>

#JS
function doClick(){
alert(document.getElementById('local-states').value)
}

Ext.onReady(function(){

var agentsStore = new Ext.data.Store({
// load using HTTP
proxy: new Ext.data.HttpProxy({url: 'xmlstore.xml'}),
// the return will be XML, so lets set up a reader
reader: new Ext.data.XmlReader({
// records will have an "Agent" tag
record: 'Agent'
}, [
'agentid', 'agentinfo'
])
});
var combo = new Ext.form.ComboBox({
hiddenName: 'local-states',
store: agentsStore,
typeAhead: true,
mode: 'local',
triggerAction: 'all',
emptyText:'Select a state...',
selectOnFocus:true,
applyTo: 'local-states',
displayField: 'agentinfo',
valueField: 'agentid'
});
agentsStore.load();
});


#XML
<?xml version="1.0" encoding="UTF-8"?>
<agents>
<Agent>
<agentid>10560</agentid>
<agentinfo>192.168.1.160 - 10560</agentinfo>
</Agent>
<Agent>
<agentid>10565</agentid>
<agentinfo>192.168.1.165 - 10565</agentinfo>
</Agent>
</agents>


Thanks,
Siddhartha.

wvmaaren
21 Jul 2009, 11:43 PM
you should add a renderer to position it's data.



// renderer for value and display
Ext.util.Format.comboRenderer = function(combo){
returnfunction(value){
var record = combo.findRecord(combo.valueField, value);
return record ? record.get(combo.displayField) : combo.valueNotFoundText;
}
}

// Create Combobox (I make this external and place the variable in the grid or toolbar)

var comboProject = new Ext.form.ComboBox({
typeAhead : true,
triggerAction : 'all',
lazyRender : true,
mode : 'local',
store : new Ext.data.ArrayStore({
id: 0,
fields: [
'myId',
'displayText'
]
}),
valueField : 'myId',
displayField : 'displayText'
});

// Add this to your columns / items section
header: 'Project',
dataIndex: 'project',
sortable: true,
width: 150,
editor: comboProject, // specify reference to combo instance
renderer: Ext.util.Format.comboRenderer(comboProject)


Goodluck

Condor
22 Jul 2009, 12:02 AM
That's completely unrelated advise!

I think that this is a conflict with id vs. name. You are using the same id for the input as the hiddenName.

You probably need to use a different id.

sidd
22 Jul 2009, 1:16 AM
Hey condor,

Thanks 4 ur reply,
I fixed the issue. I was using something else in the hiddenName. I replaced it with valueField name and it solved the issue.

i changed hiddenName: 'local-states' to hiddenName: 'agentid' .
agentid is mu valueField name.

I have just started using ext-js.i dont have a lot knowledge in it.
Am i fixed the issue in the rite way ???

Thanks,
Sidd.

Condor
22 Jul 2009, 1:44 AM
Yes, you either had to change the id of the input or the hiddenName (you used the 2nd option).