PDA

View Full Version : Quick question about programatically selecting combobox value



romerve
23 Feb 2011, 8:14 AM
Hello,

I have a combo box with values pulled from a database. I am trying to bind a gird so what when a item in the grid gets selected, it would update the form next to it and populated with the values corresponding to the selection.

I am having difficulties making the combobox select a specific value; i've tried:
selectByValue()
setValue()
setRawValue()

But even when it's value change, i cannot get the view to reflect the change.

Any ideas...?

Thanks!

johnathanhebert
23 Feb 2011, 8:42 AM
Is the combobox store loaded at that point? If the combo store is not loaded, then there is no corresponding record in the combo store for the value passed to setValue

By default, combobox will load the store the first time the trigger is clicked... If you want to load the combo store when it is created, set autoLoad:true on the combo store config, and then set mode:'local' on the combo config

drian
23 Feb 2011, 11:07 AM
First thing you need to be sure is that the datastore behind the combobox is loaded. setValue() will set the value of the combobox to the valueField of the combobox (this valueField needs to point to one field in your datastore as well).

romerve
23 Feb 2011, 1:47 PM
Well, the "mode" needs to be remote as the data source is not local.

Also, when the combobox is triggered by clicking on its trigger, the DS loads and sends a clean request, however, if i try to do something like:


Ext.getCmp('combo').store.load();


It fails because the request is wrong:


Request URL:http://localhost/ci/index.php/admin/cms/getcboxcategories?_dc=1298497286800
Request Method:GET
Status Code:404 Not Found


Note the _dc part and the method, but when i click on its trigger i see:


Request URL:http://localhost/ci/index.php/admin/cms/getcboxcategories
Request Method:POST
Status Code:200 OK


I've looked over the docs and cant find a way to change the GET to a POST. Here is my combo box:


var itemCategoryId = new Ext.form.ComboBox({
id: 'itemCategoryId',
emptyText: 'No Data...',
fieldLabel: 'Belongs to',
displayField: 'categoryName',
valueField: 'categoryId',
hiddenName: 'categoryId',
editable: false,
mode: 'remote',
triggerAction: 'all',
selectOnFocus: true,
width: 140,
store: new Ext.data.Store({
storeId: 'allCatDs',
autoDestroy: true,
autoLoad: false,
reader: new Ext.data.JsonReader({
idProperty: 'categoryId',
root: 'records',
fields: new Ext.data.Record.create([
{name: 'categoryId'},
{name: 'categoryName'},
{name: 'categoryParent'},
{name: 'linkId'}
])
}),
proxy: new Ext.data.HttpProxy({
url: './cms/getcboxcategories',
methos: 'POST'
}),
autoSave: false
})
});



Thanks for any ideas..!

romerve
23 Feb 2011, 1:50 PM
LOL never mind.... I see the typo...

My bad... Need new eyes...:D :">

johnathanhebert
23 Feb 2011, 2:02 PM
As a side note, the "mode" of the combobox can be local, even though the data is loaded remotely via the store... it is confusing, but it just means that the combo will not reload the store when the trigger is clicked the first time

Condor
24 Feb 2011, 7:43 AM
You need to use setValue(newCategoryId), but this will only work if the combobox store is loaded.

You can use this patch (http://www.sencha.com/forum/showthread.php?75751-OPEN-42-ComboBox-s-setValue-call-with-a-remotely-loaded-Store&p=400274&viewfull=1#post400274) to make a combobox load itself when calling setValue.

romerve
24 Feb 2011, 8:15 AM
Yeah, i ended up loading the DS at another step.

Thanks for the suggestion.