PDA

View Full Version : ComboBox hiddenName and setValue



oakin
3 Jun 2009, 1:52 PM
Hi all,

Here is a simple ComboBox config;


this.cmbAssignedTo = new Ext.form.ComboBox({
fieldLabel : 'Assignee',
hiddenName : 'assignedTo',
valueField : 'id',
displayField : 'userName',
store : new Ext.data.JsonStore({
autoLoad: true,
url: '/ticket/users',
fields: [ 'id', 'userName' ]
}),
width : 150
})I retrieve ticket objects from database and update the selected item on the combo with the values from the ticket.

cmbAssignedTo.setValue(ticket.assignedTo) statement works perfectly but it doesn't update the value of the hidden field inside the combo. When I post the form, if the user didn't click the combo and select an item from the list before, the value of the displayField is posted, not the value of hiddenField.

Is this a bug, or by design?

Thank you.

Animal
3 Jun 2009, 2:00 PM
If the setValue is called before the Store has finished loading (Remember it uses Ajax), then it won't be able to look up the Record.

oakin
3 Jun 2009, 2:20 PM
The store is loaded before setValue(). I tried it with autoLoad: true and store.load(). No success.

Animal
3 Jun 2009, 9:03 PM
Show me how you tried this.

oakin
3 Jun 2009, 11:37 PM
I removed irrelevant field definitions from the source.


Application.TicketForm = function(config) {

this.hdTicketId = new Ext.form.Hidden({
name : 'id'
})

this.cmbState = new Ext.form.ComboBox({
fieldLabel : 'Status',
hiddenName : 'state',
mode : 'local',
typeAhead : true,
triggerAction : 'all',
valueField : 'id',
displayField : 'name',
store : new Ext.data.JsonStore({
url: '/ticket/states',
fields: [ 'id', 'name' ]
}),
width : 150
})
this.cmbState.store.load();

this.cmbDepartment = new Ext.form.ComboBox({
fieldLabel : 'Department',
hiddenName : 'department',
mode : 'local',
typeAhead : true,
triggerAction : 'all',
valueField : 'id',
displayField : 'name',
store : new Ext.data.JsonStore({
url: '/ticket/departments',
fields: [ 'id', 'name' ]
}),
width : 150
})
this.cmbDepartment.store.load();

this.cmbAssignedTo = new Ext.form.ComboBox({
fieldLabel : 'Assigned To',
hiddenName : 'assignedTo',
mode : 'local',
typeAhead : true,
triggerAction : 'all',
valueField : 'id',
displayField : 'userName',
store : new Ext.data.JsonStore({
url: '/ticket/users',
fields: [ 'id', 'userName' ]
}),
width : 150
})
this.cmbAssignedTo.store.load();

Ext.apply(this, {
title : 'Ticket Info',
frame : true,
labelWidth : 100,
layout : 'column',
items : [
{
columnWidth : .5,
layout : 'form',
items : [
this.hdTicketId, this.cmbState
]
},
{
columnWidth : .5,
layout : 'form',
items : [
this.cmbAssignedTo, this.cmbDepartment
]
}
]
})

Ext.form.FormPanel.superclass.constructor.call(this, config);

this.setTicket = function(ticket) {
this.hdTicketId.setValue(ticket.id);
this.cmbState.setValue(ticket.state);
this.cmbDepartment.setValue(ticket.department);
this.cmbAssignedTo.setValue(ticket.assignedTo);
}

this.updateTicket = function() {
this.getForm().submit({
url: '/ticket/updateticket',
success: function(form, action) { Ext.Msg.alert('Ticket Update', action.result.msg); },
failure: function(form, action) { Ext.Msg.alert('Error!', action.result.msg); }
});
}
}

Ext.extend(Application.TicketForm, Ext.form.FormPanel);

Animal
4 Jun 2009, 12:08 AM
So has the store finished loading (http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.data.Store&member=load) through Ajax by the time you call setValue?

oakin
4 Jun 2009, 12:43 AM
Yes, exactly. This form is shown below a list of tickets. So combobox values are already loaded before the user clicks the grid and selects a ticket from the list. When the user clicks a row, setTicket function is called and I set selected values there...

As for the loading of the stores, I can clearly see the json request and response with Firebug. I am using mode='local' because if I don't, although I load the stores manually, when I click the dropdown to select an item a new request is sent. I didn't test it throughly, maybe I am wrong about this, not sure.

Animal
4 Jun 2009, 1:21 AM
<sighs>

<gives up>

oakin
4 Jun 2009, 2:53 AM
When .select() is called on combobox, it gives an error that this.view is undefined. I am debugging from the source and can see that view is created. Any ideas?

roy.scott
6 Apr 2011, 1:41 PM
Animal

<sighs>

< gives up>


@Animal: I don't want to be rude, but responses like these are not helpful and very unprofessional. I'm coming to find these types of responses to people's questions all over the forums and it is making my search for answers overly complicated as the issues are either unresolved or never truly addressed.

drian
6 Apr 2011, 9:57 PM
The ajax calls are asynchronous, which means that after you make an ajax call, javascript will jump to the other lines of code and execute them without waiting for the ajax call to be finished.

It's not like your normal php where every line is executed in the order it is written.

You should use events to trigger the functions you need to run when a store is loaded.


store.on('load', function(){
myComponent.setValue(myValue);
});

linuxguy2001
23 May 2011, 6:47 AM
@Animal: I don't want to be rude, but responses like these are not helpful and very unprofessional. I'm coming to find these types of responses to people's questions all over the forums and it is making my search for answers overly complicated as the issues are either unresolved or never truly addressed.

Scott you aren't the only one who thinks this way, some of the support on this forum is rather rude, just to put it nicely. I am also looking for the same answer (along others), so what I did in the meantime while I haven't found the answer, was creating a hidden field and set it's value then use both on post. Please let me know if you aren't sure on how to go about this and I'll help you out. You can also check out my site I created once I got fed up with replies like the one you mentioned previously. My site has quite a few examples and step by step tutorials on how to got about a whole lot of extjs stuff. My site is www.foscode.com , I've tried adding it to my signature but haven't been able to yet.