PDA

View Full Version : Change ComboBox selection by id ?



Permidion
24 Apr 2008, 2:48 AM
Hello,

I would like to know how to change a ComboBox selection by giving it the "id" of the record to display.

One can easily do that by using the "value" with mycombobox.setValue('foo'); but I would like to do something like mycombobox.setValueByID(5); which would select the 5th record.

Doing something like:


mycombobox.setValue(mycombobox.store.getAt(5).data.value);

seems overkill for something that simple.

Any better way to do that?

I tried using mycombobox.select(5); but this didnt change anything. What is it supposed doing ?

Thanks in advance

24 Apr 2008, 4:09 AM
selectValueById works perfectly for me,
can you post your combo code?

Permidion
24 Apr 2008, 5:09 AM
errrr, selectValueById doesnt exist in 2.1 as far as I know.



Ext.onReady(function(){
var converted = new Ext.form.ComboBox({
typeAhead: false,
triggerAction: 'all',
transform:'selecttest',
width:135,
forceSelection:true,
editable:false
});

converted.selectValueById(1);
});


applied on



<select name="selecttest" id="selecttest">
<option></option>
<option value="test1">test1</option>
<option value="test2">test2</option>
<option value="test3"selected="selected">test3</option>
<option value="test4">test4</option>
<option value="test5">test5</option>
</select>


will get you an "converted.selectValueById is not a function" error.

24 Apr 2008, 5:21 AM
do'h! i was thinking selectByValue, my apologies. I was just using selectByValue yesterday to set a value of a combo, but that combo returns an ID. I got my wires crossed :(

24 Apr 2008, 7:36 AM
FYI, if you use the OOTB combo box, you can 'selectValue(someId)' really easily - if you setup a store, etc.


I'm doing this for a customer right now, and it works beautifully.

Permidion
24 Apr 2008, 10:17 PM
OOTB ?

felle42
25 Apr 2008, 2:24 AM
perhaps: Out Of The Box? :-/

This is also interesting for me.
I'll see..

25 Apr 2008, 4:31 AM
yeah, out of the box ;). of course, the box is ficticous