Question

I'm using ExtJs 4 and in my Web application I have a combo box. Previously I used to set the default value of the combo box using emptyText. It works just fine. But, is there any alternative way of setting the default value for the same?

I looked into different questions here on SO and tried the following -

Ext.getCmp('myComboBoxID').setValue("myValue");

However, this doesn't seem to be working. I also tried the simple value attribute to no avail. How can I the set the default value other than using emptyText?

Also, when the value is set using emptyText, it is displayed in gray color (which is poorly vsible), I was wondering if one can work with the opacity of the ExtJs select box?

Update: I used Ext.getCmp('myComboBoxID').setRawValue("myValue"); to set the value & it worked. What is the difference between setValue() & setRawValue()?

Was it helpful?

Solution 2

I used Ext.getCmp('myComboBoxID').setRawValue("myValue"); to set the value & it worked.

OTHER TIPS

You need to supply the id to getCmp method. Try the following.

Ext.getCmp('#myComboBoxID').setValue("myValue");

The store needs to be loaded before you call setValue and you use the id of the record you want to select. There is a load event you can listen for if the values are loaded from the server. emptyText is not intended for default values, but to help the user understand what should be done with the field (eg "Select a state" from a list of states)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top