Anjan Baradwaj
Anjan Baradwaj

Reputation: 1229

Default value for ExtJs Combo box without using emptyText

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()?

Upvotes: 1

Views: 2659

Answers (3)

Anjan Baradwaj
Anjan Baradwaj

Reputation: 1229

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

Upvotes: 1

Nabarun
Nabarun

Reputation: 791

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

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

Upvotes: 2

g3k0
g3k0

Reputation: 152

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)

Upvotes: 0

Related Questions