PDA

View Full Version : ComboBox not sending right



mitchellsimoens
9 Jun 2009, 7:23 PM
I have a ComboBox that has get it's data from a php script


new Ext.form.ComboBox({
triggerAction: 'all',
name: 'forum',
id: 'forum',
mode: 'local',
lazyInit: true,
displayField: 'name',
valueField: 'id',
typeAhead: true,
inputType: 'text',
fieldLabel: 'Forums',
allowBlank: false,
store: new Ext.data.JsonStore({
autoLoad: true,
baseParams: {
task: "GET-FORUMS"
},
url: 'functions.php',
root: 'results',
fields: ['id', 'name']
})
})

but when I send it it sends the name field and not the id. I want it to send the id field. I've looked around and can't seem to figure it out. Please help...

BitPoet
9 Jun 2009, 11:49 PM
Have a look at the hiddenName (http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.form.ComboBox&member=hiddenName) property in the ComboBox, which you need to set. Make sure to set a hiddenId different from the id itself.

Animal
9 Jun 2009, 11:53 PM
This has been FAQed for a long time: http://extjs.com/learn/Ext_FAQ_ComboBox#submit_.22valueField.22_instead_of_.22displayField.22

mitchellsimoens
10 Jun 2009, 2:35 PM
Ok, you're gonna call me stupid but it's still sending the text not the value. Here is my code please tell me where I'm going wrong if you could.


new Ext.form.ComboBox({
triggerAction: 'all',
name: 'forum',
id: 'forum',
mode: 'local',
lazyInit: true,
displayField: 'name',
valueField: 'id',
hiddenName: 'forum_id_name',
hiddenId: 'forum_id',
typeAhead: true,
inputType: 'text',
fieldLabel: 'Forums',
allowBlank: false,
shadow: "drop",
store: new Ext.data.JsonStore({
autoLoad: true,
baseParams: {
task: "GET-FORUMS"
},
url: 'functions.php',
root: 'results',
fields: ['id', 'name']
})
})

So it's sending the displayText and not the valueField still

Animal
11 Jun 2009, 12:00 AM
So the HTTP parameter forum_id_name is the displayed text??? Weird. There must be something else going on here.

mitchellsimoens
12 Jun 2009, 8:21 AM
Maybe this will help, my whole form with the submit handler....


var postForm = new Ext.FormPanel({
labelWidth: 75,
url:'functions.php',
id: 'postForm',
frame:true,
title: 'Post Topic',
bodyStyle:'padding:5px 5px 0',
autoHeight: true,
autoWidth: true,
defaults: {width: 230},
defaultType: 'textfield',
items: [
new Ext.form.ComboBox({
triggerAction: 'all',
name: 'forum',
id: 'forum',
mode: 'local',
lazyInit: true,
displayField: 'name',
valueField: 'id',
hiddenName: 'forum_id_name',
hiddenId: 'forum_id',
typeAhead: true,
inputType: 'text',
fieldLabel: 'Forums',
allowBlank: false,
shadow: "drop",
store: new Ext.data.JsonStore({
autoLoad: true,
baseParams: {
task: "GET-FORUMS"
},
url: 'functions.php',
root: 'results',
fields: ['id', 'name']
})
}),{
fieldLabel: 'Title',
name: 'title',
id: 'title',
allowBlank: false
},{
xtype:'htmleditor',
name: 'post',
id:'post',
fieldLabel:'Post',
height:200,
anchor:'98%'
}

],
buttons: [{
text: 'Post',
listeners: {
click: function(b) {
submitHandler();
}
}
},{
text: 'Cancel',
listeners: {
click: function(b) {
postForm.getComponent("title").setValue("");
postForm.getComponent("post").setValue("");
vp.getComponent("southRegion").collapse();
}
}
}]
});

var onSuccessorFail = function(form, action) {
var formPanel = Ext.getCmp("postForm");
formPanel.el.unmask();

var result = action.result;
if (result.success) {
Ext.MessageBox.alert("Success", action.result.msg);
} else {
Ext.MessageBox.alert("Failure", action.result.msg)
}
}

var submitHandler = function() {
var formPanel = Ext.getCmp("postForm");
formPanel.el.mask("Please Wait", "x-mask-loading");

formPanel.getForm().submit({
url: "functions.php?task=ADD-POST&uname="+uname,
success: onSuccessorFail,
failure: onSuccessorFail
})
}

and yes, in my PHP code, I'm using the forum_id_name to get the value

Animal
12 Jun 2009, 8:45 AM
You have to debug.

mitchellsimoens
12 Jun 2009, 8:54 AM
ok, but my Ext JS code is correct... fun time starts

Animal
12 Jun 2009, 9:01 AM
Well, in some way, some of your code is not correct.

So you have to poke the DOM to see what's being put into the hidden field.

If that's not what you expect, then you have to examine what's in the Store.

All quite run of the mill debugging jobs that developers have to do every day.

mitchellsimoens
12 Jun 2009, 9:05 AM
I suppose you wouldn't want to point out what in my code is not correct

Animal
12 Jun 2009, 11:40 PM
I can't see it!

Sometimes you HAVE to debug!

It's what we (developers) DO!