PDA

View Full Version : combobox valueField



winpygsfli
21 Aug 2009, 8:53 AM
I have the follwoing combo box in a form panel. It works great except it send the name field instead of the value field to my php script. I have read that you have to use a hidden field to store the value but I keep getting JS errors. Any help would be great. Am I close or way out in left field?


Ext.onReady(function(){
Ext.QuickTips.init();
var combo = new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
lazyRender:true,
fieldLabel:'Code',
mode: 'local',
store: new Ext.data.ArrayStore({
id: 0,
fields: [
'id',
'code',
'name'
],
data: [[0, 'VC', 'Vacation'], [1, 'OT', 'Overtime']]
}),
valueField: 'code',
displayField: 'name',
hiddenName:'hiddenCode',
name: 'code',
allowBlank:false
});
var hidden = new Ext.form.Hidden({
name:'loginUsername'
});
var login = new Ext.FormPanel({
labelWidth:80,
url:'login.php' (http://extjs.com/forum/'login.php'),
frame:true,
title:'Please Login',
defaultType:'textfield',
monitorValid:true,
items:[{
fieldLabel:'Username',
name:'loginUsername',
allowBlank:false
},{
fieldLabel:'Password',
name:'loginPassword',
inputType:'password',
allowBlank:false
},hidden,combo ],

// All the magic happens after the user clicks the button
buttons:[{
text:'Login',
formBind: true,
// Function that fires when user clicks the button
handler:function(){
login.getForm().submit({
method:'POST',
waitTitle:'Connecting',
waitMsg:'Sending data...',

// Functions that fire (success or failure) when the server responds.

success:function(){
Ext.Msg.alert('Status', 'Login Successful!', function(btn, text){
if (btn == 'ok'){
var redirect = 'index.html';
window.location = redirect;
}
});
},
failure:function(form, action){
if(action.failureType == 'server'){
obj = Ext.util.JSON.decode(action.response.responseText);
Ext.Msg.alert('Login Failed!', obj.errors.reason);
}else{
Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText);
}
login.getForm().reset();
}
});
}
}]
});


// This just creates a window to wrap the login form.
// The login object is passed to the items collection.
var win = new Ext.Window({
layout:'fit',
y:20,
x: 20,
width:300,
height:175,
closable: false,
resizable: false,
plain: true,
border: false,
items: [login],
modal: true
});
win.show();
});

winpygsfli
21 Aug 2009, 11:54 AM
I was able to fix it by intializing my data store before loading the combobox.



var store = new Ext.data.ArrayStore({
id: 0,
fields: [
'id',
'code',
'name'
],
data: [[0, 'VC', 'Vacation'], [1, 'OT', 'Overtime']]
});
var combo = new Ext.form.ComboBox({
typeAhead: true,
triggerAction: 'all',
lazyRender:true,
fieldLabel:'Code',
mode: 'local',
store: store,
valueField: 'code',
displayField: 'name',
hiddenName:'hiddenCode',
name: 'code',
allowBlank:false
});