PDA

View Full Version : Question about combo box



hometownnerd
3 Jun 2013, 9:07 AM
I am extremely new to ext.js and I am using code that someone else has created that builds a combo box, but what I need is to have the combo box actually auto select an entry in it on load, I have tried to use the render listener but I am facing a new issue. The dropdown actually auto selects as it should but the dropdown seems to use an ID instead of the value stored in the dropdown, how can I force this to auto select. When you normally select the drop down it shows just the username, when it actually getValue it uses the ID, I cannot seem to have it do this through setValue, show the username but set the user id. does this make sense?

Thanks in advance for any help that can be provided.
The code is below:


var UserListcbo = new Ext.form.ComboBox({
id:'UserListcbo',
fieldLabel: 'Member',
loadingText:'Please Wait ...',
store:UsersDataDS,
mode: 'local',
forceselection:true,
displayField: 'username',
valueField: 'ID',
anchor:'95%',
triggerAction: 'all',
value: 'USERNAME',//this is the username to fill in the dropdown on load
listeners:{
select:function(combo,record){
uid = UserListcbo.getValue();
username = record.data.username;
//on user select load trip and pictures for user
TripDataDS.load({params: {mode: 'TripList',UID: uid}});
AllPicturesDS.load({params: {mode:'AllPictures',UID: uid}});
},
render:function(combo,record){
uid = USERID;//the user id of the user you want to select
username = "USERNAME";//the username you want to select
//on user select load trip and pictures for user
TripDataDS.load({params: {mode: 'TripList',UID: uid}});
AllPicturesDS.load({params: {mode:'AllPictures',UID: uid}});
}


}


});

mitchellsimoens
5 Jun 2013, 5:30 AM
Thank you for using BBCode CODE tags for your code but you need to ensure it's legible for people to help you and understand your code. Can you restore the indention?

hometownnerd
5 Jun 2013, 5:57 AM
var UserListcbo = new Ext.form.ComboBox({
id:'UserListcbo',
fieldLabel: 'Member',
loadingText:'Please Wait ...',
store:UsersDataDS,
mode: 'local',
forceselection:true,
displayField: 'username',
valueField: 'ID',
anchor:'95%',
triggerAction: 'all',
value: 'USERNAME',//this is the username to fill in the dropdown on load
listeners:{
select:function(combo,record){
uid = UserListcbo.getValue();
username = record.data.username;
//on user select load trip and pictures for user
TripDataDS.load({params: {mode: 'TripList',UID: uid}});
AllPicturesDS.load({params: {mode:'AllPictures',UID: uid}});
},
render:function(combo,record){
uid = USERID;//the user id of the user you want to select
username = "USERNAME";//the username you want to select
//on user select load trip and pictures for user
combo.setValue(uid);

TripDataDS.load({params: {mode: 'TripList',UID: uid}});
AllPicturesDS.load({params: {mode:'AllPictures',UID: uid}});
}

}

});



Sorry, didn't even pay attention to how it looked, thanks! Hope this is better.

guilan
7 Jun 2013, 7:44 AM
Hi hometownnerd:

I am completely new in this area. I tried to use your suggestion to solve my problem, but I encountered the error 'getValue is not a function'. My problem is that my combo box always returns the first item not the item selected. Here is the part of my code:
items: [{
id: 'banner1',
xtype: "combo",
//editable: false,
width: 700,
listWidth: 700,
store: store,
displayField: 'banner',
valueField: 'event_id',
name: 'banner1',
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
emptyText:'No Banner',
selectOnFocus:true,
listeners:{
select:function(combo,record){
event_id = banner1.getValue();
banner= record.data.banner;
}
}
}]

Any help is appreciated. Thank you for your help in advance.